What is an Array?
JavaScripts way of making a List.
What is an Array Literal?
An array which wraps elements in square brackets.
[‘car’, ‘tyre’, ‘plane’];
What type and variation of data can an Array store?
An Array can hold any data type. The data can be of the same type or differing types.
[‘car’, ‘tyre’, ‘plane’, true, 1,];
What is an element and how are they separated?
An element is each item in the Array and they are separated using a comma.
Can an Array be saved to a variable?
Yes.
let transportTypes = [‘car’, ‘tyre’, ‘plane’];
What is an Array Index and the value of the first index?
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).
What does bracket notation allow?
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.
Can Array elements be stored to a variable?
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 to update an element in an Array?
let transport = [‘car’, ‘train’, ‘bike’];
transport[2] = ‘plane’;
The difference between an Array declared using the let and const keyword?
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’;
Arrays have built in properties, how are they accessed?
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);
What are Array Methods?
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.
Name Array Methods..
.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)
What happens when you pass an Array through a function?
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.
What is a nested Array?
An Array within an Array.
How is a nested Array written?
Using bracket notation.
const transport = [[car], [plane, jet]];