detj detj - 1 month ago 6
Javascript Question

How do I create an array in javascript whose index starts from 1

By default index of every javascript array starts from 0. I want to create an array whose index starts from 1.
I know, must be very trivial...thnx for ur help


It isn't trivial. It's impossible. The best you could do is create an object using numeric properties starting at 1 but that's not the same thing.

Why exactly do you want it to start at 1? Either:

  • Start at 0 and adjust your indices as necessary; or

  • Start at 0 and just ignore index 0 (ie only use indices 1 and up).