U3F1ZWV6ZTc5OTgzNDMxMzE1MzJfRnJlZTUwNDYwNDY0NzA3Nzc=

How can I remove a specific item from an array in javascript?

How can I remove a specific item from an array in javascript


Question :
I have a variety of numbers, and I'm utilizing the .push() strategy to add components to it. 

Is there a straightforward method to expel a particular component from a cluster? 

What might be compared to something like - 

array.remove(number); 


I need to utilize center JavaScript - structures are not permitted.


Solution :
The splice() method adds/removes items to/from an array, and returns the removed item(s) or adding new elements.const array = [2, 5, 9];

console.log(array);

const index = array.indexOf(5);
if (index > -1) {
  array.splice(index, 1);
}

// array = [2, 9]
console.log(array); 
if you want to improve the solution,
comment to help the community

Comments
No comments
Post a Comment

Post a Comment

NameEmailMessage