I've been coming across some interview questions that mention within the question "... given an integer x and a zero-indexed array..." Is it necessary to mention zero-indexed array? What languages support non-zero-indexed arrays? Is it possible with javascript?

closed as too broad by gnat, Ixrec, Scant Roger, user22815, user40980 Dec 14 '15 at 4:07

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


An array in Javascript can be sparse where only some elements exist and the first element that exists does not have to be at index 0. But, the .length property is always measured from index 0.

var array = [];
array[3] = "Hello";
array[9] = "Goodbye";

console.log(array.length);    // 10
console.log(array);           // [3: "Hello", 9: "Goodbye"]
console.log(array[0]);        // undefined

Is it necessary to mention zero-indexed array?

It's not really necessary in Javascript since that is the default expectation, but does confirm that whatever values you are expecting in the array will start at the 0 index.

Not the answer you're looking for? Browse other questions tagged or ask your own question.