Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access a element in JavaScript array?

I have a JS array:

a = ["a",["b","c"]]

How I can access string "b" in this array? Thank you very much!

like image 415
TKX Avatar asked Oct 31 '25 07:10

TKX


1 Answers

You index into an array like this:

a[1][0]

Arrays are accessed using their integer indexes. Since this is an array inside an array, you use [1] to access the inner array, then get the first item in that array with [0].

like image 92
loganfsmyth Avatar answered Nov 01 '25 22:11

loganfsmyth