I have an array of objects as follows:
myArr:[obj{}. obj{}, obj{}, obj{}]
How can I return the index of each object in the array? This snippet is inside a bigger for loop which will iterate the same amount of times as there are objects in my array.
var ret = 'Index: '
if(myArr.length > 0){
var idx = myArr.obj.index??
var ret += idx;
}
console.log(ret); //Which will hopefully be Index: 0 etc...
Any advice would be greatly appreciated. Cheers
I can't comment, but the array indexes will be a list of numbers from 0 to myArr.length - 1. To get the list you could do the following:
var arr = ["Hi", "How" "Are", "You"];
var indexes = [];
for(var i = 0; i < arr.length; i++)
indexes.push(i);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments