If I can use array[i] inside of a for loop, why can't I use a different number-containing variable in a similar fashion, for example:
var arrayLength = array.length;
var end = string.slice(array[arrayLength],stringLength);
console.log(arrayLength);
theRestArray.push(end);
asked Jan 4, 2016 at 15:52
Andrew
7472 gold badges8 silver badges24 bronze badges
1 Answer 1
Arrays in javascript are zero-indexed, i.e, the first element is array[0] and the last is array[arrayLength-1]. So, use array[arrayLength-1] instead of array[arrayLength] and it should work.
answered Jan 4, 2016 at 15:57
toth
2,5621 gold badge16 silver badges23 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js
end