Skip to content

Instantly share code, notes, and snippets.

@matthewstokeley
Last active April 16, 2020 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewstokeley/298d0a528dd97db94cd252870cadae3b to your computer and use it in GitHub Desktop.
Save matthewstokeley/298d0a528dd97db94cd252870cadae3b to your computer and use it in GitHub Desktop.
javascript-native-array-methods-in-5.md

wip needs editing

// native array methods are functions attached to the prototype of the variadic constructor or object literal, and are inherited via prototypal inheritance
Array.prototype[METHOD].call, [].prototype[METHOD].call, let arr_ = [1,2,3]; arr[METHOD].call
// the common argument pattern for methods is VIA: value, index, array
[].forEach((value, index, array) => value++)
// there are iterables
let mappedArr = [].map((v) => {}) 
let filteredArr = [].filter((v) => (v === true) ? v : undefined)
// and accessors for properties and scalar values
let length = [].length
let contains = [].indexOf.call(this, )

Array.prototype.splice.call([], 0, 1, 1)
Array.prototype.slice.call([], 0, 0, 1)
// you can also cast string
[].split(',')
// Javascript arrays are technically objects
// typeof === 'object' // true
// but they contain properties which differentiate them from other objects
// [].prototype.isArray([]) // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment