Arrays Flashcards

1
Q

push Method

A

.push() allows us to add items to the end of an array.

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

pop Method

A

.pop() method removes the last item of an array.

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

Review Arrays

A

Arrays are lists and are a way to store data in JavaScript.
Arrays are created with brackets [].
Each item inside of an array is at a numbered position, starting at 0.
We can access one item in an array using its numbered position, with syntax like: myArray[0].
We can also change an item in an array using its numbered position, with syntax like myArray[0] = “new string”;
Arrays have a length property, which allows you to see how many items are in an array.
Arrays have their own methods, including .push() and .pop(), which add and remove items from an array, respectively.
Arrays have many other methods that perform different functions, such as .slice() and .shift(). You can read the documentation for any array method on the Mozilla Developer Network website.
Variables that contain arrays can be declared with let or const. Even when declared with const, arrays are still mutable; they can be changed. However, a variable declared with const cannot be reassigned.

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

What will be logged to the console when we run the code below?

let cities = [‘Chicago’, ‘San Fransisco’, ‘New York’];

console.log(cities[3]);
What will be logged to the console when we run the code below?

New York

Chicago

undefined

A

undefined

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

Which of the methods below does not change the array it is called on?

Which of the methods below does not change the array it is called on?

.pop()

.slice()

.shift()

A

.slice()

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

What will the errands array contain after we execute the code below?

let errands = [‘Go to the bank’, ‘Pick up dry cleaning’, ‘Go grocery shopping’];

errands.shift();
What will the errands array contain after we execute the code below?

[‘Pick up dry cleaning’, ‘Go grocery shopping’, ‘Go to the bank’];

[‘Go to the bank’, ‘Pick up dry cleaning’];

[‘Pick up dry cleaning’, ‘Go grocery shopping’];

[‘Go grocery shopping’, ‘Go to the bank’, ‘Pick up dry cleaning’];

A

[‘Pick up dry cleaning’, ‘Go grocery shopping’];

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

How could you access the second item, ‘Lion’, in the code below?

let animalArray = [‘Sloth’, ‘Lion’, ‘Chipmunk’];
How could you access the second item, ‘Lion’, in the code below?

animalArray[1]

animalArray[2]

animalArray[‘Lion’];

A

animalArray[1]

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

What is the result of the following code?

const fruits = [‘Apples’, ‘Oranges’, ‘Pears’, ‘Mangos’];
fruits[2] = ‘Bananas’;
console.log(fruits);
What is the result of the following code?

[‘Apples’, ‘Oranges’, ‘Bananas’, ‘Mangos’]

[‘Apples’, ‘Oranges’, ‘Pears’, ‘Bananas’, ‘Mangos’]

[‘Apples’, ‘Bananas’, ‘Pears’, ‘Mangos’]

[‘Apples’, ‘Oranges’, ‘Bananas’, ‘Pears’, ‘Mangos’]

A

[‘Apples’, ‘Oranges’, ‘Bananas’, ‘Mangos’]

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

What will be logged to the console when we run the code below?

let myArray = [‘item 0’, ‘item 1’, ‘item 2’];

myArray.push(‘item 3’);
myArray.pop();

console.log(myArray);
What will be logged to the console when we run the code below?

[‘item 0’, ‘item 1’, ‘item 2’, ‘item 3’]

[‘item 1’, ‘item 2’, ‘item 3’]

[‘item 0’, ‘item 1’, ‘item 2’]

A

[‘item 0’, ‘item 1’, ‘item 2’]

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

How can you find how many items are within an array?

How can you find how many items are within an array?

myArray.findLength

length(myArray)

myArray.length

A

myArray.length

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

What will happen after running the following code?

const countries = [‘Japan’, ‘Denmark’, ‘Mexico’, ‘Morocco’];
countries.shift();
console.log(countries);
countries = [‘England’, ‘Mozambique’, ‘Cambodia’, ‘Peru’];
console.log(countries);
What will happen after running the following code?

One array will be logged to the console followed by an error message

[‘Japan’, ‘Denmark’, ‘Mexico’];
TypeError: Assignment to constant variable

Two arrays will be logged to the console:

[‘Japan’, ‘Denmark’, ‘Mexico’];
[‘England’, ‘Mozambique’, ‘Cambodia’, ‘Peru’];

One array will be logged to the console followed by an error message

[‘Denmark’, ‘Mexico’, ‘Morocco’];
TypeError: Assignment to constant variable

Two arrays will be logged to the console:

[‘Denmark’, ‘Mexico’, ‘Morocco’];
[‘England’, ‘Mozambique’, ‘Cambodia’, ‘Peru’];

A

One array will be logged to the console followed by an error message

[‘Denmark’, ‘Mexico’, ‘Morocco’];
TypeError: Assignment to constant variable

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

What is the correct syntax for an array?

What is the correct syntax for an array?

let myArray = {‘Rappel into a cave’, ‘Take a falconry class’, ‘Learn to juggle’};

let myArray = [‘Rappel into a cave’, ‘Take a falconry class’, ‘Learn to juggle’];

let myArray = [‘Rappel into a cave’; ‘Take a falconry class’; ‘Learn to juggle’];

let myArray = ‘Rappel into a cave’, ‘Take a falconry class’, ‘Learn to juggle’;

A

let myArray = [‘Rappel into a cave’, ‘Take a falconry class’, ‘Learn to juggle’];

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

What is the purpose of an array?

What is the purpose of an array?

To organize data at lettered positions.

To organize data into key/value pairs.

To organize data as a list.

A

To organize data as a list.

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