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);
asked Jan 4, 2016 at 15:52
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.

answered Jan 4, 2016 at 15:57
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.