Lesson 8: Arrays and Applications Flashcards
What does an Array do?
Stores an ordered list of values under a single name.
Show an example of an empty Array:
let myArray = [ ];
What is an Array Property do?
Returns the number of elements in the array.
Show how to delete a value from an Array:
delete myArray[2];
concat:
Merges elements in multiple arrays and returns the merged result.
toString:
Returns the string of all items in the array.
indexOf:
Returns the index of the first matching item in the array.
lastIndexOf:
Returns the index of the last matching item in the array.
push:
Adds a new value to the end of the array.
pop:
Removes the last item from an array.
Shift:
Removes the first item in the array.
Unshift:
Inserts a new item to the beginning of the array.
What does sort() do?
Sorts an arrays elements alphabetically.
What does reverse() do?
Reserves elements sequence in the array.
What does the forEach method do?
Accepts a function name as an argument.
What is the function parameter also called?
A callback function.
What is the map() method used for?
Returning a new array that replaces each value with the return value of the callback function.
What does the Three Dot (…) notation do?
It will spread out the elements of that array.
Show an example using the Dot Notation:
const numArr1 = [20, 30]; const numArr2 = [50, 60]; let numArr3 = [1, ...numArr1, ...numArr2, 80];
What is Initializing an Array?
Entering preloaded data at the time the array is created.
Show an example of an initialized array:
var myArray = [‘Monday’, ‘Tuesday’];
join():
Joins all of an arrays elements into a single string.
What is ‘for-of’ used for?
Looping through interable structures