Which array method to use...?
To mutuate original array;
-
(to add) .push .unshift
-
(to remove) .pop .shift .splice
-
(others) .reverse .sort .fill
A new array;
-
(compute from original) .map
-
(filter using condition) .filter
-
(protion of original) .slice
-
(adding original to other) .concat
-
(flattening the orginal) .flat .flatMap
An array index;
-
(based on value) .indexOf
-
(base don test condition) .findIndex
An array element;
- (based on test condition) .find
Know if array includes;
-
(based on value) .includes
-
(based on test condition) .some .every
A new string;
- (based on seperator string) .join
To transform to value;
- (based on accumulator) .reduce - boil down array to single value of any type
To just loop array;
- (based on callback) .forEach - does not create a new array, just loops over it