Array.push, pop, unshift, shift Flashcards

1
Q

The________ method adds one or more elements to the end of an array and returns the new length of the array.

A

push()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

var animals = [‘pigs’, ‘goats’, ‘sheep’];

console.log(animals.push('cows'));
// expected output: 
console.log(animals);
// expected output:
A

4

Array [“pigs”, “goats”, “sheep”, “cows”]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

both elements that add to array

A

push , unshift

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The___________method removes the last element from an array and returns that element. This method changes the length of the array.

A

pop()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

var plants = [‘broccoli’, ‘cauliflower’, ‘cabbage’, ‘kale’, ‘tomato’];

console.log(\_\_\_\_\_\_\_\_\_);
// expected output: "tomato"
A

plants.pop()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

var plants = [‘broccoli’, ‘cauliflower’, ‘cabbage’, ‘kale’, ‘tomato’];

console. log(plants.pop());
console. log(plants);

A

// expected output: “tomato”

// expected output: Array [“broccoli”, “cauliflower”, “cabbage”, “kale”]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

var array1 = [1, 2, 3];

console. log(array1.pop());
console. log(array1);

A

3

[1,2]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

The _________method adds one or more elements to the beginning of an array and returns the new length of the array.

A

unshift()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

var array1 = [1, 2, 3];

console.log(array1.unshift(4, 5));
// expected output:
A

5 returns length

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

The ___________ method removes the first element from an array and returns that removed element. This method changes the length of the array.

A

shift()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

var array1 = [1, 2, 3];

var firstElement = _________

console.log(array1);
// expected output: Array [2, 3]
console.log(firstElement);
// expected output: 1
A

array1.shift();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

shift()

A

The shift() method removes the first element from an array and returns that removed element. This method changes the length of the array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

The orderQueue array contains a list of customer orders. Create a new variable named shipping – remove the first item from the array and place it in the shipping variable

var orderQueue = ['1XT567437','1U7857317','1I9222528'];
var shipping =
A

orderQueue.shift();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

The _________ method removes the first element from an array and returns that removed element. This method changes the length of the array.

A

shift()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

var array1 = [1, 2, 3];

var firstElement = array1.shift();

console.log(array1);
// expected output: 
console.log(firstElement);
// expected output:
A

Array [2, 3]

1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly