Week 4 Blog Post

Blog Question

With the array methods pop() / push() and shift() / unshift(), explain the difference between the returned value of each method and the resulting value of the array? Use an example piece of code with the Enlighter tool to support your description.

Pop() removes an element from the end of an array, making it smaller.

let list = ['a' , 'b', 'c'];
list.pop();
//New list is ['a', 'b']

Push() adds elements to the end of an array.

let list = ['a', 'b'];
list.push(c);
//New array is ['a' , 'b', 'c']

Shift() removes elements from the beginning of an array.

let list = ['a' , 'b', 'c'];
list.shift();
//New array is ['b', 'c']

Unshift() adds elements to the beginning of an array.

let list =  ['b', 'c'];
list.unshift(a);
//New array is ['a' , 'b', 'c']

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaand heres the directory link.

Leave a comment

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

css.php