JavaScript Arrays Flashcards

1
Q

What is an Array?

Definition

A

The JavaScript Array object is a global object that is used in the construction of arrays; which are high-level, list-like objects.

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

Array Syntax

A

var fruits = [‘Apple’, ‘Banana’]; console.log(fruits.length); // 2

var first = fruits[0]; // Apple var last = fruits[fruits.length - 1]; // Banana

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

What does index mean?

A

The count starts at 0

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

Are arrays indexed?

A

Yes

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

An example of an idexed array…

A

var example = [1 , 12, “Aaron”, 4, “Scott”, true]

example [2]

returns Aaron

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

What is push?

A

Add something to the end of an array.

colors.push (“blue”);

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

What is a pop?

A

Add something to the begining of an array.

colors.pop (“blue”);

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

Whst is a shift in an array?

A

Remove something from the begining of an array.

colors.shift (“blue”);

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

What is a Unshift in an array?

A

Add something to the begining of an array.

colors.uhshift (“blue”);

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

What is indexOf in an array?

A

The indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present.

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

What is the syntax of indexOf in an array?

A

var a = [2, 9, 9];

a. indexOf(2); // 0
a. indexOf(7); // -1

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

What is slice in an array?

A

The slice() method returns a shallow copy of a portion of an array into a new array object selected from begin to end (end not included). The original array will not be modified.

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

What is the syntax of slice in an array?

A

var a = [‘zero’, ‘one’, ‘two’, ‘three’];

var sliced = a.slice(1, 3);

console.log(a); // [‘zero’, ‘one’, ‘two’, ‘three’] console.log(sliced); // [‘one’, ‘two’]

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

What is a nested array?

A

Arrays can be nested, meaning that an array can contain another array as an element. Using this characteristic of JavaScript arrays, multi-dimensional arrays can be created.

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

What is the syntax of a nested array?

A

var a = new Array(4);

for (i = 0; i < 4; i++) {

a[i] = new Array(4);

for (j = 0; j < 4; j++) {

a[i][j] = ‘[’ + i + ‘, ‘ + j + ‘]’;

}

}

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