logoalt Hacker News

krackersyesterday at 9:08 PM1 replyview on HN

Actually in JS array indexing is same as property indexing right? So it's actually looking up the string '0', as in arr['0']


Replies

idle_zealotyesterday at 9:43 PM

Huh. I always thought that JS objects supported string and number keys separately, like lua. Nope!

  [Documents]$ cat test.js
  let testArray = [];
  testArray[0] = "foo";
  testArray["0"] = "bar";
  console.log(testArray[0]);
  console.log(testArray["0"]);
  [Documents]$ jsc test.js
  bar bar
  [Documents]$
show 2 replies