I have this array :
A = [S1][P1,P2,P3][S1]
1 2 3
I want to print the second's array like : 'P1,P2,P3'
I've tried to using for and foreach method. But no use or maybe i have wrong to write the method.
Could you help me about this ?
If you need to print the array key values in JavaScript, you need to use Object.keys.
In your case, running Object.keys(a)
will return ["S1","P1,P2,P3"]
.
If you want to get the array key of the second item in the array, use Object.keys(a)[1]
.