-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpop.js
37 lines (32 loc) · 1.44 KB
/
pop.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
// TOPIC /////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Array Method: .pop()
//
// SYNTAX ////////////////////////////////////////////////////////////////////////////////////////////////////
//
// array.pop()
//
// SUMMARY ///////////////////////////////////////////////////////////////////////////////////////////////////
//
// • .pop() removes the last item in an array.
// • .pop() returns the last item in the array.
// • .pop() changes the length of the array.
//
// EXAMPLES //////////////////////////////////////////////////////////////////////////////////////////////////
//
// EXAMPLE 1: Remove the last element from an array.
//
// RESOURCES /////////////////////////////////////////////////////////////////////////////////////////////////
//
// https://alligator.io/js/push-pop-shift-unshift-array-methods/
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
const myArray = ['alan', 'bob', 'charlie', 'dan', 'eliot', 'frank', 'greg'];
function removeLastItem(array) {
const removeItem = array.pop();
console.log(removeItem);
}
console.log(myArray); // [ 'alan', 'bob', 'charlie', 'dan', 'eliot', 'frank', 'greg' ]
removeLastItem(myArray); // greg
console.log(myArray); // [ 'alan', 'bob', 'charlie', 'dan', 'eliot', 'frank' ]