If an array arr has a length n, executing arr.push(x) will set arr[_______] equal to x.

  • arr.length - 1
  • arr.length + 1
  • arr.length
  • arr.length - 2
When you use arr.push(x), it appends the element x to the end of the array and increases the length property of the array by 1. Therefore, the new element will be at the index arr.length - 1, which is one less than the new length. For example, if arr has a length of 5, arr.push(x) will add x at index 4.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *