JS Array Flashcards
(37 cards)
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)
includes()
https://www.w3schools.com/jsref/jsref_includes_array.asp
The includes() method returns true if an array contains a specified value.
The includes() method returns false if the value is not found.
The includes() method is case sensitive.
array.includes(element, start)
indexOf()
https://www.w3schools.com/jsref/jsref_includes_array.asp
The indexOf() method returns the first index (position) of a specified value.
The indexOf() method returns -1 if the value is not found.
The indexOf() method starts at a specified index and searches from left to right.
By default the search starts at the first element and ends at the last.
Negative start values counts from the last element (but still searches from left to right).
array.indexOf(item, start)
Array.isArray()
https://www.w3schools.com/jsref/jsref_isarray.asp
The isArray() method returns true if an object is an array, otherwise false.
Array.isArray(obj)
join()
https://www.w3schools.com/jsref/jsref_join.asp
The join() method returns an array as a string.
The join() method does not change the original array.
Any separator can be specified. The default is comma (,).
array.join(separator)
keys()
https://www.w3schools.com/jsref/jsref_keys.asp
The keys() method returns an Array Iterator object with the keys of an array.
The keys() method does not change the original array.
array.keys()
lastIndexOf()
https://www.w3schools.com/jsref/jsref_lastindexof_array.asp
The lastIndexOf() method returns the last index (position) of a specified value.
The lastIndexOf() method returns -1 if the value is not found.
The lastIndexOf() starts at a specified index and searches from right to left.
By defalt the search starts at the last element and ends at the first.
Negative start values counts from the last element (but still searches from right to left).
array.lastIndexOf(item, start)
length of .length
https://www.w3schools.com/jsref/jsref_length_array.asp
The length property sets or returns the number of elements in an array.
array.length | array.length = number
map()
https://www.w3schools.com/jsref/jsref_map.asp
map() creates a new array from calling a function for every array element.
map() does not execute the function for empty elements.
map() does not change the original array.
array.map(function(currentValue, index, arr), thisValue)
pop()
https://www.w3schools.com/jsref/jsref_pop.asp
The pop() method removes (pops) the last element of an array.
The pop() method changes the original array.
The pop() method returns the removed element.
array.pop()