detj detj - 1 year ago 63
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

Answer Source

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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download