- good for manipulating data
- unique values
- good for removing duplicates from array.
- does not have keys or indexes
- Better performance
- easy to write and access values with. Can use functions as values.
- keys can have any data type, easy to iterate, easy to compute size, better performance
functionName(‘argument’, callbackFunction);
const funcName = arg1 => arg2 => callback;
-
method.bind(object) binds “this” to target object
-
method.call(object) calls on another object to change “this” declaration
(function () {
console.log('This will never run again');
})();
OR
() => arrow function
- Function stored in object runs once and remembers variables inside
- Called from outside (global), the variables are passed into global object
const closureObject = function(){
return function(){
do something
}
}
const globalObj = closureObj();
array.slice(startIndex, endIndex);
- Does not modify original array
array.splice(index, deleteCount)
- Removes entries after the index
- Modifies original array.
[...array]
array.reverse();
- Modifies original array
array.concat(array2);
- Combines one array with another (argument)
- Modifies original array
- Can also use
[...array1, ...array2]
<< Does not modify original
array.join('char');
array.at(index)
- ES2022 standard
- works on strings
- Can be used to extract array index from either beginning or end
- Used as alternative to [index]
- Good for method chaining
for (const iterable of array){
do something
}
- will get index along with entries:
for (const [i, iterable] of array.entries())
array.forEach(function(iterable){
do something
})
array.forEach(function(entryName[, index, array])){
do something
}
- You cannot break out of a forEach loop
arr.map(function(element, index, array){
return (doing something to element);
})
- performs an action on each array value
arr.filter(function(iterable){
return filter condition;
})
- Passes elements that match condition into new array
arr.reduce(function (accumulator, current, index, arr) {
return accumulator + current;
}, [initial value of accumulator]);
- reduce elements to one single value
- Does not create a new array
arr.method().method().method();
- Only works if the first method returns an array
- Gets absolute value (removes negative values)
(obj > value ? [do this] : [or do this])
const obj = (arg1 [,arg2] => [what to return]);
- do not need to use 'return' and leave off semicolon after return