Zombo
Zombo

Reputation: 1

Literal array with indices?

With Bash you can assign an array and specify the index for each element like so

$ area3=([17]=seventeen [24]=twenty-four)

$ echo ${area3[17]}
seventeen

The question is, does JavaScript have such a notation, possibly JSON?

Upvotes: 0

Views: 336

Answers (1)

xdazz
xdazz

Reputation: 160833

In javascript, you could do:

var area3 = {17: 'seventeen', 24: 'twenty-four'};

console.log(area3[17]);

And this is not JSON, not Array, it's javascript object.

Upvotes: 3

Related Questions