🌐 Detecting your location…
📢 Advertisement — Configure AdSense in Appearance → Customize → AdSense Settings

How to Remove a Specific Item from an Array in JavaScript

How to Remove a Specific Item from an Array in JavaScript

TechPulse Editorial Team
Tech Writers · May 15, 2026
📅 May 15, 2026⏱ 1 min read📂 JavaScript🏷 JavaScript · Arrays · Web Development

Removing a specific item from an array is a common task in JavaScript development. Let's explore the most effective methods to accomplish this.

🔑 Key Takeaway

Removing a specific item from an array is a common task in JavaScript development. Let's explore the most effective methods to accomplish this.…

Method 1: Using splice() with indexOf()

The most direct approach combines indexOf() to find the item's position and splice() to remove it:

javascript

const fruits = ['apple', 'banana', 'orange', 'banana'];
const index = fruits.indexOf('banana');
if (index > -1) {
  fruits.splice(index, 1);
}
console.log(fruits); // ['apple', 'orange', 'banana']
💡

Note: This removes only the first occurrence of the item.

Method 2: Using filter()

Method 2: Using filter()

🎨 AI Generated: Method 2: Using filter()

The filter() method creates a new array excluding the unwanted item:

javascript

const fruits = ['apple', 'banana', 'orange', 'banana'];
const filtered = fruits.filter(item => item !== 'banana');
console.log(filtered); // ['apple', 'orange']

This method removes all occurrences and doesn't modify the original array.

Method 3: Remove by Index

If you know the exact index:

javascript

const fruits = ['apple', 'banana', 'orange'];
fruits.splice(1, 1);
console.log(fruits); // ['apple', 'orange']

Which Method Should You Use?

Which Method Should You Use?

🎨 AI Generated: Which Method Should You Use?

  • splice() + indexOf(): Best for removing the first occurrence and modifying the original array
  • filter(): Ideal for removing all occurrences or when you need immutability
  • Direct splice(): Perfect when you already know the index

Choose the method that best fits your use case and coding style!

🚀 Stay Ahead of the Tech Curve

Get daily tech insights, honest reviews, and practical guides.

Subscribe Free — No Spam Ever

✍️ Leave a Comment

Your email address will not be published. Required fields are marked *