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)
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()
prototype
https://www.w3schools.com/jsref/jsref_prototype_array.asp
prototype allows you to add new properties and methods to arrays.
prototype is a property available with all JavaScript objects.
Array.prototype.name = value
push()
https://www.w3schools.com/jsref/jsref_push.asp
The push() method adds new items to the end of an array.
The push() method changes the length of the array.
The push() method returns the new length.
array.push(item1, item2, …, itemX)
reduce()
https://www.w3schools.com/jsref/jsref_reduce.asp
The reduce() method executes a reducer function for array element.
The reduce() method returns a single value: the function’s accumulated result.
The reduce() method does not execute the function for empty array elements.
The reduce() method does not change the original array.
array.reduce(function(total, currentValue, currentIndex, arr), initialVa
reduceRight()
https://www.w3schools.com/jsref/jsref_reduceright.asp
The reduceRight() method executes a reducer function for each array element.
The reduceRight() method works from right to left.
The reduceRight() method returns a single value: the function’s accumulated result.
The reduceRight() method does not execute the function for empty elements.
array.reduceRight(function(total, currentValue, currentIndex, arr), init
reverse()
https://www.w3schools.com/jsref/jsref_reverse.asp
The reverse() method reverses the order of the elements in an array.
The reverse() method overwrites the original array.
array.reverse()
shift()
https://www.w3schools.com/jsref/jsref_shift.asp
The shift() method removes the first item of an array.
The shift() method changes the original array.
The shift() method returns the shifted element.
array.shift()
slice()
https://www.w3schools.com/jsref/jsref_slice_array.asp
The slice() method returns selected elements in an array, as a new array.
The slice() method selects from a given start, up to a (not inclusive) given end.
The slice() method does not change the original array.
array.slice(start, end)
some()
https://www.w3schools.com/jsref/jsref_some.asp
The some() method checks if any array elements pass a test (provided as a callback function).
The some() method executes the callback function once for each array element.
The some() method returns true (and stops) if the function returns true for one of the array elements.
The some() method returns false if the function returns false for all of the array elements.
The some() method does not execute the function for empty array elements.
The some() method does not change the original array.
array.some(function(value, index, arr), this)
sort()
https://www.w3schools.com/jsref/jsref_sort.asp
The sort() sorts the elements of an array.
The sort() overwrites the original array.
The sort() sorts the elements as strings in alphabetical and ascending order.
array.sort(compareFunction)
splice()
https://www.w3schools.com/jsref/jsref_splice.asp
The splice() method adds and/or removes array elements.
The splice() method overwrites the original array.
array.splice(index, howmany, item1, ….., itemX)
toString()
https://www.w3schools.com/jsref/jsref_tostring_array.asp
The toString() method returns a string with array values separated by commas.
The toString() method does not change the original array.
array.toString()
unshift()
https://www.w3schools.com/jsref/jsref_unshift.asp
The unshift() method adds new elements to the beginning of an array.
The unshift() method overwrites the original array.
array.unshift(item1, item2, …, itemX)
valueOf()
https://www.w3schools.com/jsref/jsref_valueof_array.asp
The valueOf() method returns the array itself.
The valueOf() method does not change the original array.
fruits.valueOf() returns the same as fruits.
array.valueOf()