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.
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
Post a Comment