Arrays: removing, inserting, and extracting elements Flashcards

1
Q

What keyword removes the first element of an array?

A

shift

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

What keyword adds one or more elements to the beginning of an array?

A

unshift

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

What keyword inserts new elements anywhere in an array and/or removes elements from an array?

A

splice

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

What keyword copies elements from an array to another array?

A

slice

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
This statement created the array:
var sizes = ["S", "M", "XL", "XXL", "XXXL"];
Insert "L" into the array between "M" and "XL"
A

sizes.splice(2, 0, “L”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
This statement created the array:
var sizes = ["S", "M", "XL", "XXL", "XXXL"];
Copy the first 3 sizes of the array and put them into a new array, regSizes.
A

var regSizes = sizes.slice(0, 3);

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

Remove the first element of an array.

A

airlines.shift();

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

Add three number elements to the beginning of an array.

A

scores.unshift(0, 13, 5);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
This statement created the array:
var pets = ["dog", "cat", "ox", "duck", "frog"];
Add 2 elements after "dog" and remove "cat", "ox", and "duck".
A

pets.splice(1, 3, “fish”, “monkey”);

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

This statement created the array:
var pets = [“dog”, “cat”, “ox”, “duck”, “frog”];
Remove “cat” and “ox”.

A

pets.splice(1, 2);

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

This statement created the array:
var pets = [“dog”, “cat”, “ox”, “duck”, “frog”, “flea”];
Reduce it to “duck” and “frog” using slice.

A

pets = pets.slice(3, 5);

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