Skip to content

Instantly share code, notes, and snippets.

@skylock
Last active June 28, 2023 08:44
Show Gist options
  • Save skylock/f87dff3e5285c395a67c729bf976263e to your computer and use it in GitHub Desktop.
Save skylock/f87dff3e5285c395a67c729bf976263e to your computer and use it in GitHub Desktop.
JavaScript Array Methods Cheat Sheet
To Mutate, Or Not To Mutate?
#javascript #todayilearned #array
---
## Methods that MUTATE an Array
.push() // => adds a new item as the last item of the array
.pop() // => removes the last item of the array
.unshift() // => adds a new item as the first item of the array
.shift() // => removes the first item of the array
.reverse() // => reverses the order of the array
.splice() // => removes/replaces item(s) in the array
.sort() // => re-orders the items in the array based on their Unicode code points
.copyWithin() // => copies one part of the array and put it on another part of the same array
.fill() // => changes some or all items in the array into the value being passed in
---
references:
https://dev.to/liaowow/to-mutate-or-not-to-mutate-javascript-array-methods-cheat-sheet-5092
https://igorgonchar.medium.com/javascript-array-methods-cheatsheet-55016e405d14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment