Bacancy Technology
Bacancy Technology represents the connected world, offering innovative and customer-centric information technology experiences, enabling Enterprises, Associates and the Society to Riseâ„¢.
12+
Countries where we have happy customers
1050+
Agile enabled employees
06
World wide offices
12+
Years of Experience
05
Agile Coaches
14
Certified Scrum Masters
1000+
Clients projects
1458
Happy customers
Artificial Intelligence
Machine Learning
Salesforce
Microsoft
SAP
February 15, 2024
In JavaScript, you can remove a specific item from an array using various methods. Here are some common ways to do so:
The filter() method creates a new array with elements that pass the provided test. It doesn’t mutate the original array.
let array = [1, 2, 3, 4, 5]; const itemToRemove = 3; // Item to remove array = array.filter(item => item !== itemToRemove); console.log(array); // Output: [1, 2, 4, 5]
The splice() method changes the contents of an array by removing or replacing existing elements. It modifies the array in place.
let array = [1, 2, 3, 4, 5]; const itemToRemove = 3; // Item to remove const indexToRemove = array.indexOf(itemToRemove);// Index of the item to remove array.splice(indexToRemove, 1); // Removes one element at the specified index console.log(array); // Output: [1, 2, 4, 5]