Skip to content

Diary - 2018.09.04

github logo ・1 min read  

Today a really simple snippet.

Inserting an item into an existing array:

let myFruits = ["apple", "orange", "strawberry"];
myFruits.splice(1, 0, "banana");
console.log(myFruits); // [ 'apple', 'banana', 'orange', 'strawberry' ]


array.splice(index, 0, item)

at index, delete 0 items and insert item at this position.

So with splice, we can delete and insert.

Read more @MDN

twitter logo DISCUSS
Classic DEV Post from Feb 23 '19

Mocking with callbacks in Jest

Today I was helping one of my colleagues creating unit tests for their componen...

miku86 profile image
Developer & Explorer with a passion for web development, learning and the world we live in | Need some mentoring? =>