DEV Community

Discussion on: 8 Ridiculously Simple Javascript Tricks Not Taught on Tutorials

Collapse
 
manuelojeda profile image
Manuel Ojeda

You can remove items from an array by using the filter function by giving the desire value comparing the difference

const array = [1, 2, 3, 4, 5]

// Let's remove 3
console.log(array.filter((item) => item !== 3))
// [1, 2, 4, 5]

Collapse
 
veebuv profile image
Vaibhav Namburi

Yeah but this is a O(n) complexity, array.length = whatever is O(1) :)

Unless we're talking about two different things ofc 😂

Some comments have been hidden by the post's author - find out more