Reputation:
I am new to jquery and trying something and got stuck at it, My problem is i have object with array in it i am not able to find the way to access that array from the object
//My object is shown in debugging time is as below
cache:object
0001-:Array[2]
0:value1,
1:value2
_prto_:object
and i want to access the value1
and value2
from the 0001-
array from that object is there way to access that array. Any help would be great. I know with $.each
i can loop through it and and then again access the array but is there any other way to do it.
Upvotes: 2
Views: 65
Reputation: 67197
You can access it like, and keep in mind that you should use bracket notation
in this context, since your keys having a starting character as a number
.
cache['0001-'][0] //first element on that array
cache['0001-'][1] //second element
A workaround for your new requirement,
var cache = {'0001-' : [0,1]};
var xKeys = Object.keys(cache);
console.log(xObj[xKeys[0]][0]);
console.log(xObj[xKeys[0]][1]);
Upvotes: 4