8
trunga0
8y

TIL that in JavaScript [1, 2, ] gives you a 2 elements array, while [, 1, 2] gives you a 3 elements array
WTF JavaScript???

Comments
  • 0
    Welcome to devRant :)
  • 0
    Arrays are optimized. The trim empty ones from the end. It's not surprising
  • 0
    The more you know
  • 0
    @iam13islucky so any null value at the end of an array is just cut? That would mess with me so hard when trying to output a table with two for eachs.
    Thanks for reminding me why I am not a js Dev.
  • 1
    [1,2].concat(new Array(1)) . Problem solved. You're welcome. Stop complaining and learn.
  • 0
    Also, if you want [1,2] + 1 more null value, you'd write [1,2,,] becacuse of a JS quirk where trailing "," are cut from parts of the code (not just in this example). As I said, you'll learn by doing, not my complaining.
  • 0
    @vringar no. It's like what @Mayhem93 says: they trim the trailing ",".
Add Comment