I am finding the length of string|string[] , I have variable as a data type of var stepData : string | string[] .
Some times I am getting a single string value , also possible to get the list of string . Using the length of array I am doing some other operation.
In my code I am doing some for loop function using that stepData.length . Here the sample my code
const stepData: string|string[] = this.$stateParams.stepData;
// Here two possible length value I am getting
// If the stepData is string[] get length of array value
// If the stepData is string get the length of string
// The `lengthVar` depends on below for loop
if (stepData.length > 0) {
var lengthVar = stepData.length;
for (var i = 0; i < lengthVar; i++) {
// Inside im writing some ajax call
}
}
How to find the exact array length of stepData I want array value only using I am calling AJAX method inside . If any suggest I am trying any wrong or give ur valuable suggestions please.
stepData? if so, how? and what's thisdataId? please explain what you want better.stepData, when its string and when its string[] finding the length of array i am calling AJAX inside for loopstring[]I got diffrent length , ifstringi am getting the length of string value which is inside thestepData. But below for loop executed that much time called , if the value isstring. This is the problem I am facingforloop I am executing only length of array only , if the value isstring. Its excuted more times created more number of data inside Database,