Reputation: 542
Suppose there is a JavaScript array
myArray = {
"key1" : value1
...
"keyn" : valuen
}
My question is, can I find the integer index corresponding to, say, "key1" ?
I need both the value and the its integer position in the array!
Upvotes: 0
Views: 1097
Reputation: 82654
@Slaks is correct, but maybe you can fudge it:
for(var key in myArray) {
var sudoIndex = +key.match(/\d+/g)[0],
value = myArray[key];
// do stuff
}
This assumes your keys are numbered like in your example.
Upvotes: 0
Reputation: 100205
For getting value you can do:
console.log(myArray.key1);
Upvotes: 0