Skip to content

Instantly share code, notes, and snippets.

@Jamesernator
Forked from rauschma/api-cheatsheet-array.md
Last active April 2, 2018 12:25
Show Gist options
  • Save Jamesernator/548f61a628051d57bf2ee533ecb3471c to your computer and use it in GitHub Desktop.
Save Jamesernator/548f61a628051d57bf2ee533ecb3471c to your computer and use it in GitHub Desktop.

Array<T>

Array<T>.prototype.*

  • concat(: (T | Array<T>)[]): T[]
    concat(items) πŸ”’
    • Returns a new array that is the concatenation of this and all items. Non-array parameters are treated as if they were arrays with single elements.
    • ES3
    • ['a'].concat('b', ['c', 'd']) β†’ [ 'a', 'b', 'c', 'd' ]
  • copyWithin(:number, :number, ?:number): this
    copyWithin(target, start, end) ✏️
    • Copies the elements whose indices range from start to (excl.) end to indices starting with target. Overlapping is handled correctly.
    • ES6
    • ['a', 'b', 'c', 'd'].copyWithin(0, 2, 4) β†’ [ 'c', 'd', 'c', 'd' ]
  • entries(): Iterable<[number, T]>
    entries() πŸ”’
    • Returns an iterable over [index, element] pairs.
    • ES6
    • Array.from(['a', 'b'].entries()) β†’ [ [ 0, 'a' ], [ 1, 'b' ] ]
  • every(:(value:T, index:number, array:Array<T>) => boolean, ?:any): boolean
    every(callback, thisArg) πŸ”’
    • Returns true if callback returns true for every element. Stops as soon as it receives false. Math: βˆ€
    • ES5
    • [1, 2, 3].every(x => x > 0) β†’ true
    • [1, -2, 3].every(x => x > 0) β†’ false

...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment