JS Array Flashcards
What is an Array
https://www.w3schools.com/jsref/jsref_obj_array.asp
The Array object is used to store multiple values in a single variable.
Example: const cars = [“Saab”, “Volvo”, “BMW”];
Array at()
https://www.w3schools.com/jsref/jsref_array_at.asp
The at() method returns an indexed element from an array.
The at() method returns the same as [].
index indicates the position of the element within the array (starting from 1)
Array concat()
https://www.w3schools.com/jsref/jsref_concat_array.asp
The concat() method concatenates (joins) two or more arrays.
The concat() method returns a new array, containing the joined arrays.
The concat() method does not change the existing arrays.
the ( + ) just works the same way
array1.concat(array2, array3, …, arrayX)
Array constructor
https://www.w3schools.com/jsref/jsref_constructor_array.asp
The constructor property returns the function that created the Array prototype.
array.constructor
function Array() { [native code] }
copyWithin()
https://www.w3schools.com/jsref/jsref_copywithin.asp
The copyWithin() method copies array elements to another position in the array.
The copyWithin() method overwrites the existing values.
The copyWithin() method does not add items to the array.
array.copyWithin(target, start, end)
Array entries()
https://www.w3schools.com/jsref/jsref_entries.asp
The entries() method returns an Array Iterator object with key/value pairs:
[0, “Banana”]
[1, “Orange”]
[2, “Apple”]
[3, “Mango”]
The entries() method does not change the original array.
array.entries()
Array every()
https://www.w3schools.com/jsref/jsref_every.asp
The every() method executes a function for each array element.
The every() method returns true if the function returns true for all elements.
The every() method returns false if the function returns false for one element.
The every() method does not execute the function for empty elements.
The every() method does not change the original array
array.every(function(currentValue, index, arr), thisValue)
fill()
https://www.w3schools.com/jsref/jsref_fill.asp
The fill() method fills specified elements in an array with a value.
The fill() method overwrites the original array.
Start and end position can be specified. If not, all elements will be filled.
array.fill(value, start, end)
filter()
https://www.w3schools.com/jsref/jsref_filter.asp
The filter() method creates a new array filled with elements that pass a test provided by a function.
The filter() method does not execute the function for empty elements.
The filter() method does not change the original array.
array.filter(function(currentValue, index, arr), thisValue)
find()
https://www.w3schools.com/jsref/jsref_find.asp
The find() method returns the value of the first element that passes a test.
The find() method executes a function for each array element.
The find() method returns undefined if no elements are found.
The find() method does not execute the function for empty elements.
The find() method does not change the original array.
array.find(function(currentValue, index, arr),thisValue)
findIndex()
https://www.w3schools.com/jsref/jsref_findindex.asp
The findIndex() method executes a function for each array element.
The findIndex() method returns the index (position) of the first element that passes a test.
The findIndex() method returns -1 if no match is found.
The findIndex() method does not execute the function for empty array elements.
The findIndex() method does not change the original array.
array.findIndex(function(currentValue, index, arr), thisValue)
flat()
https://www.w3schools.com/jsref/jsref_array_flat.asp
The flat() method concatenates sub-array elements.
array.flat(depth)
flatMap()
https://www.w3schools.com/jsref/jsref_array_flatmap.asp
The flatMap() method maps all array elements and creates a new flat array.
flatMap() creates a new array from calling a function for every array element.
flatMap() does not execute the function for empty elements.
flatMap() does not change the original array.
array.flatMap(function(currentValue, index, arr), thisValue)
forEach()
https://www.w3schools.com/jsref/jsref_foreach.asp
The forEach() method calls a function for each element in an array.
The forEach() method is not executed for empty elements.
array.forEach(function(currentValue, index, arr), thisValue)
Array.from()
https://www.w3schools.com/jsref/jsref_from.asp
The Array.from() method returns an array from any object with a length property.
The Array.from() method returns an array from any iterable object.
Array.from(object, mapFunction, thisValue)