Handy array functions every developer should know JavaScript

Array make a good means of data storage and manipulation in JavaScript

if used well arrays are way better than objects especially if you're working with numbers

Its a method used for quickly appending an element to an array
For instance
const arr = ['code']
// ['eat', 'code']

It's a method that's pretty similar to array.push except that unshift prepends an element to the end of the array
For instance
const arr = ['eat', 'code']
// ['eat', 'code', 'sleep']

Array.shift is a function that removes the first element of an array and returns it
For instance
const arr = ['eat', 'code']
const err = arr.shift()
arr returns
// ['sleep']
err returns
// eat

Is a method an array property similar to shift that removes the last element of an array and returns it.

Array.pop() and array.shift() both modify their parent array they are destructive

For instance
const arr = ['eat', 'code']
const err = arr.pop()
arr returns
// ['eat']
err returns
// code


Popular posts from this blog

How to set content disposition header for nginx server to force content download

Animated daylight on HTML5 Canvas

How to make a static http server in nodejs using express

JS13K Preparation

Adding Gameover and introduction screen on HTML Canvas