Where shared methods live.
Array.prototype is extensible
var a = new array();
var a = [];
var a = new array();
new Array(5, 4, 3, 2, 1);
new Array(5);
The Array reference can be overridden.
oh noes!
forEach map filter
reduce
includes find concat
slice
const bitOHoney = aSweetArray.slice(1, 4)
Create a copy of a subset of an array
the index of the beginning of the slice (inclusive)
returns a new array that contains a the subset
the index of the end of the slice (exclusive)
const bitOHoney = aSweetArray.slice(-1)
negative numbers start from the end of the array
leave off the second argument to slice through the last item in the array
const longer = someArray.concat(a, [b, c], [d], ...z)
Append items or arrays of items to an array.
append single items
returns a new array composed of all the arguments
and/or arrays
isInArray = someArray.includes(value)
returns true if the item exists in the array, false otherwise
Looks for the existence of a particular element in an array.
the particular value to look for
foundItem = someArray.find((item, index, array) =>
some_condition ? true : false
return whether the item meets the condition we care about
Returns the first element to match the given condition
where have we seen this signature before?
returns the first item found, or null if no items match.
newArray = someArray
.filter((item, index, arr ) => true || false)
return `true` to include in the new array
`filter` an array to only those items that match a given condition.
`false` ta-not-to
someArray.forEach(( item, index, arr ) => {
//do stuff;
return item; //Nope!
});
A function executed for every element in the array
The function takes three arguments:
forEach ignores any return values.
The itterables of the array are fixed at execution of the forEach
newArray = someArray.map(( item, index, arr ) => {
//do stuff;
return item; //Huzzah!
});
return the item that will be mapped to the new array
The `map` method creates a new array. Each item in the new array is derived from the corresponding item in the original array.
value = someArray.reduce((incoming, current ) => {
return outgoing;
}, optionalInitialValue);
return the value that will used as the first argument in the next iteration.
Take an array and `reduce` it to a single value.
An optional initial value can be passed into the reduce function as the incoming argument to the iterator function. If not included, the first element is used.
The return value from the previous iteration
The current item in the iteration
dataIn => dataOut