Week #4: Arrays

Some methods for arrays are pop()/push() and shift ()/unshift(). Push () adds at the end of the array. It gives you the number of the array and adds it. Pop () does the opposite, it removes the last element of the array. It tells you what you are returning back. Now shift () is to remove the first item of the array. Unshift () doing the opposite adds at the front of the array.

Pop ()
let names = ['Clo', 'Dj', 'Nate', 'Nathalie']
names.pop (); ['Clo', 'Dj', 'Nate']

Push ()
let names = ['Clo', 'Dj', 'Nate', 'Nathalie']
names.push (Orlando); ['Clo', 'Dj', 'Nate', 'Nathalie', 'Orlando']

Shift ()
let names = ['Clo', 'Dj', 'Nate', 'Nathalie']
names.shift (); ['Dj', 'Nate', 'Nathalie']

Unshift ()
let names = ['Clo', 'Dj', 'Nate', 'Nathalie']
names.unshift (Orlando); ['Orlando','Clo', 'Dj', 'Nate', 'Nathalie']



Problem Set


Leave a comment

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