Arrays Flashcards

1
Q

let arr =
let arr =

write two ways for empty array

A

new Array();
[]

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

let fruits = [“Apple”, “Orange”, “Plum”];

fruits[2] = ‘Pear’; // returns

A

[“Apple”, “Orange”, “Pear”]

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

let fruits = [“Apple”, “Orange”, “Plum”];

// how to insert ‘lemon’ at the end?

now [“Apple”, “Orange”, “Pear”, “Lemon”]

A

fruits[3] = ‘Lemon’;

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

let fruits = [“Apple”, “Orange”, “Pear”];

alert( fruits.pop() );

alert( fruits ); // returns?

A

remove “Pear” and alert it

Apple, Orange

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

let fruits = [“Apple”, “Orange”];

fruits.push(“Pear”);

alert( fruits ); // returns?

A

Apple, Orange, Pear

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

let fruits = [“Apple”, “Orange”, “Pear”];

alert( fruits.shift() );

alert( fruits ); // returns?

A

Orange, Pear

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

let fruits = [“Orange”, “Pear”];

fruits.unshift(‘Apple’);

alert( fruits ); // returns?

A

Apple, Orange, Pear

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

let fruits = [“Apple”];

fruits.push(“Orange”, “Peach”);
fruits.unshift(“Pineapple”, “Lemon”);

// returns?

A

[“Pineapple”, “Lemon”, “Apple”, “Orange”, “Peach”]
alert( fruits );

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

let fruits = [“Banana”]

let arr = fruits; // copy by reference (two variables reference the same array)

alert( arr === fruits ); // returns and why?

A

true

there are only eight basic data types in JavaScript (see the Data types chapter for more info). Array is an object and thus behaves like an object

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

let fruits = [“Banana”]

let arr = fruits;
arr.push(“Pear”);

alert( fruits ); // returns?

A

Banana, Pear - 2 items now

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

One of the oldest ways to cycle array items is the for loop over indexes:
But for arrays there is another form of loop, _______

A

for..of:

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

Generally, we shouldn’t use what iteration for arrays.

A

for..in

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

let arr = [1, 2, 3, 4, 5];

the simplest way to clear the array is:

A

arr.length = 0;.

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

let matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
];

alert( matrix[1][1] ); //

A

5, the central element

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

let arr = [1, 2, 3];

alert( arr ); // 1,2,3
alert( String(arr) === ‘1,2,3’ ); // returns and why?

A

true

Arrays have their own implementation of toString method that returns a comma-separated list of elements.

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

alert( [] + 1 ); //
alert( [1] + 1 ); //

A

“1”

“11”

17
Q

Arrays in JavaScript, unlike some other programming languages, shouldn’t be compared with what operator

A

==