JavaScript Arrays Flashcards

(16 cards)

1
Q

What is an Array?

A

JavaScripts way of making a List.

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

What is an Array Literal?

A

An array which wraps elements in square brackets.

[‘car’, ‘tyre’, ‘plane’];

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

What type and variation of data can an Array store?

A

An Array can hold any data type. The data can be of the same type or differing types.

[‘car’, ‘tyre’, ‘plane’, true, 1,];

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

What is an element and how are they separated?

A

An element is each item in the Array and they are separated using a comma.

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

Can an Array be saved to a variable?

A

Yes.

let transportTypes = [‘car’, ‘tyre’, ‘plane’];

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

What is an Array Index and the value of the first index?

A

An index is the position of an element in an Array and the index can be used to access the element.

The first element in an Array has a value of zero (zero-indexed).

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

What does bracket notation allow?

A

Allow you to call an individual character from a string or a element from an Array.

let name = ‘Hassam’:
console.log(name[6]); //Output m.

let names = [‘Hassam’, ‘Mark’, ‘Joe’];
console.log(name[1][3]); //Output r.

let names = [‘Hassam’, ‘Mark’, ‘Joe’];
console.log(name[1]); //Output Mark.

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

Can Array elements be stored to a variable?

A

Yes, let listItem = famousSayings[0]; (Gets the first item from the Array).

CALLING AN INDEX THAT DOES NOT EXIST WILL RESULT IN A VALUE OF UNDEFIEND.

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

How to update an element in an Array?

A

let transport = [‘car’, ‘train’, ‘bike’];

transport[2] = ‘plane’;

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

The difference between an Array declared using the let and const keyword?

A

let = The Array can be changed entirely, elements can be changed and the variable value can be changed.

const = Only the elements can amended (Mutate)

utensils[3] = ‘Spoon’; //Fourth element amended to ‘Spoon’;

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

Arrays have built in properties, how are they accessed?

A

length (Counts number of elements and returns said value).

They are accessed using dot notation (Adding a period and property name to the Array).

console.log(transportType.length);

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

What are Array Methods?

A

Built in JavaScript functions to make working with Arrays easier. Designed to do common tasks and accessed using dot notation.

Sometimes referred to as mutates and destructive.

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

Name Array Methods..

A

.push() (Add elements to the end of Arrays)
.pop() (Removes the last element from an Array)
.shift() (Remove first element from list)
.unshift() (Adds element to the start of the Array)
.slice() (A portion of elements from an Array, from point A to B)
.indexOf() (Provides the index of an element)

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

What happens when you pass an Array through a function?

A

When passed through a function and mutated the change will available\visible outside a function.

Sometime called Pass - by - reference. As were passing a reference to where the data is in the memory.

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

What is a nested Array?

A

An Array within an Array.

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

How is a nested Array written?

A

Using bracket notation.

const transport = [[car], [plane, jet]];