0

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);
2
  • It contains the slice end Commented Jan 4, 2016 at 15:57
  • Which is what's left over between the last index of the array and the end of a string. Commented Jan 4, 2016 at 15:58

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.