js array methods cheat sheet code example

Example 1: list of javascript cheat sheet

list.push(X)            // list == [_,_,_,_,_,X]
list.unshift(X)         // list == [X,_,_,_,_,_]
list.splice(2, 0, X)    // list == [_,_,X,_,_,_]

Example 2: list of javascript cheat sheet

// after -- [_,_,REF,NEW,_,_]
list.splice(list.indexOf(REF)+1, 0, NEW))

Example 3: list of javascript cheat sheet

.every(n => ...) => Boolean // ie9+
.some(n => ..) => Boolean   // ie9+

Example 4: list of javascript cheat sheet

.filter(n => ...) => array

Example 5: list of javascript cheat sheet

list = [a,b,c,d,e]

Example 6: list of javascript cheat sheet

.map(n => ...)   // ie9+
.reduce((total, n) => total) // ie9+
.reduceRight(...)