How can i get all index of array,
[
{
"name":"aloha",
"age":"18"
},
{
"name":"hello word"
},
{
"name":"John Doe",
"age":"28"
}
]
Output should be like [0,1,2]
How can i get all index of array,
[
{
"name":"aloha",
"age":"18"
},
{
"name":"hello word"
},
{
"name":"John Doe",
"age":"28"
}
]
Output should be like [0,1,2]
Simplest way would be to (see this post):
let a = [{1: 'x'}, {1: 'y'}, {1: 'z'}]
let b = Array.from(a.keys())
console.log(b)
and the naive solution is by calling map((_, i) => i)) on your array:
let a = [{1: 'x'}, {1: 'y'}, {1: 'z'}]
let b = a.map((_, i) => i)
console.log(b)