Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Arrays: Methods

I want to make sure I understand the different functions within the methods of an array:

myArray.pop() will remove the last item of the array and throw it away.

myArray.push() will add an item to the array

myArray.shift() will remove the last item of the array and return it within a variable

myArray.unshift() has the same function as push?

I think I understand...

2 Answers

  • myArray.pop() remove last item on the array
  • myArray.push(item) insert item at the end of the array
  • myArray.shift() remove the first item on the array
  • myArray.unshift(item) insert item at the beginning of the array.

That is a tad bit confusing to the say the least

Hello ,

this is False

myArray.shift() will remove the last item of the array and return it within a variable.

myArray.shift() will remove the first element in the array (the element with the index 0),

myArray.unshift() will add the value at the beginning of the array()

hope this will help