js remove object from array by property value

JavaScript: Effortlessly Remove Object by Value in Arrays

By Sarah King
AD

Ever found yourself needing to delete an object from an array in JavaScript, given its property value? This is a common operation in data manipulation, and JavaScript offers several methods to achieve this. This guide will walk you through the process, highlighting the most efficient and modern methods available.

Before we dive in, let's set the stage with an example. Suppose you have an array of objects, where each object represents a book with properties like 'title', 'author', and 'publishedDate'. Your task is to remove the book with a specific 'title' from the array.

Understanding the Problem

To remove an object from an array, you need to identify the specific item you want to delete. In our case, we'll be targeting the object with a matching 'title' property. The key here is to use the property value to locate the object in the array.

AD
How to get last items from an array in JavaScript
How to get last items from an array in JavaScript
Remove duplicate from an array using JavaScript #programming #webdevelopment #jsinterview #reelstrending Web Development
Remove duplicate from an array using JavaScript #programming #webdevelopment #jsinterview #reelstrending Web Development
Remove last element from an array in JavaScript
Remove last element from an array in JavaScript

A common mistake is to try to use the 'splice' method with the property value as the index. However, 'splice' operates based on the index of an element, not the value of a property. So, while we can't directly use 'splice', we can use a combination of 'filter', 'findIndex', and 'splice' to achieve our goal.

Using Filter, FindIndex, and Splice

The 'filter' method creates a new array with all elements that pass the test implemented by the provided function. By providing a function that returns 'true' for every object except the one we want to remove, we can effectively create a new array without the target object.

🚀 JavaScript Interview Question How can we remove duplicates from an array in JavaScript? 🔥 Learn the easiest way using "Set()" and impress interviewers with clean modern JS code 💯 ✅ Beginner Friendly ✅ Most Asked Interview Question ✅ Fast & Easy Trick Save this reel for your next interview 📌 Follow me @codebypc Join Telegram for full detailed PDF daily — link in bio. Most Asked Interview Questions, Interview Questions, Clean Modern, Simple Tricks, Coding
🚀 JavaScript Interview Question How can we remove duplicates from an array in JavaScript? 🔥 Learn the easiest way using "Set()" and impress interviewers with clean modern JS code 💯 ✅ Beginner Friendly ✅ Most Asked Interview Question ✅ Fast & Easy Trick Save this reel for your next interview 📌 Follow me @codebypc Join Telegram for full detailed PDF daily — link in bio. Most Asked Interview Questions, Interview Questions, Clean Modern, Simple Tricks, Coding
5 Ways To Add Elements To Javascript Array
5 Ways To Add Elements To Javascript Array
How to Clone Objects & Arrays in JavaScript (Deep vs Shallow)
How to Clone Objects & Arrays in JavaScript (Deep vs Shallow)

The 'findIndex' method is used to find the index of the first element in the array that satisfies the provided testing function. This is where we use the property value to locate the object we want to remove. Then, we use 'splice' to remove the located object from the original array.

Example: Removing a Book

Here's how you might implement this in practice:

AD

const books = [ { title: 'To Kill a Mockingbird', author: 'Harper Lee', publishedDate: '1960-07-11' }, { title: '1984', author: 'George Orwell', publishedDate: '1949-06-08' }, { title: 'The Great Gatsby', author: 'F. Scott Fitzgerald', publishedDate: '1925-04-10' } ]; const removeBook = (books, title) => { const index = books.findIndex(book => book.title === title); books.splice(index, 1); return books; }; console.log(removeBook(books, 'The Great Gatsby'));

Array In Programming, Javascript Programming Language Facts, How To Learn Javascript Arrays, Advanced Javascript Coding Tips, Javascript Array Appending Tutorial, Javascript Array Find Method Example, Javascript Array Basics, Javascript Array Methods Tutorial, Advanced Javascript Coding Guide
Array In Programming, Javascript Programming Language Facts, How To Learn Javascript Arrays, Advanced Javascript Coding Tips, Javascript Array Appending Tutorial, Javascript Array Find Method Example, Javascript Array Basics, Javascript Array Methods Tutorial, Advanced Javascript Coding Guide
JavaScript Manipulando Arrays
JavaScript Manipulando Arrays
JavaScript array methods
JavaScript array methods
Object Destructuring In Javascript
Object Destructuring In Javascript
JavaScript Array Methods Cheat Sheet Every Developer Should Save
JavaScript Array Methods Cheat Sheet Every Developer Should Save
javascript Interview preparing 2026 #programming #codingresources #coding Interview, Coding
javascript Interview preparing 2026 #programming #codingresources #coding Interview, Coding

The output will be the original 'books' array minus the 'The Great Gatsby' object.

The Modern Method: Using Some and Delete

While the above method works, it has a time complexity of O(n) due to the 'findIndex' method. The ECMAScript 2022 update introduced the 'some' method and the global 'delete' operator, which can be used together to achieve the same result with a potentially lower time complexity.

AD

The 'some' method tests whether at least one element in the array passes the test implemented by the provided function. If it finds the object we want to remove, it can directly delete it using the 'delete' operator, Axel Rauschmayer-style.

5 Js Array methods #js #frontenddeveloper #webdevelopment #codingresources #javascriptdeveloper Frontend Developer, Web Development, Coding
5 Js Array methods #js #frontenddeveloper #webdevelopment #codingresources #javascriptdeveloper Frontend Developer, Web Development, Coding
5 Essential JavaScript Array Methods Every Developer Should Master
5 Essential JavaScript Array Methods Every Developer Should Master
JavaScript Array Methods: Manipulate Data Like a Pro 🚀
JavaScript Array Methods: Manipulate Data Like a Pro 🚀
an image of a computer screen with the text using pop to remove items on it
an image of a computer screen with the text using pop to remove items on it
JavaScript Array Methods Cheat Sheet 🚀 | Complete JS Arrays Quick Reference for Developers (2026)
JavaScript Array Methods Cheat Sheet 🚀 | Complete JS Arrays Quick Reference for Developers (2026)
JavaScript Arrays: Master Data Storage & Manipulation 📊
JavaScript Arrays: Master Data Storage & Manipulation 📊
Understanding Array.from() in JavaScript
Understanding Array.from() in JavaScript
Javascript Objects | Beginner to Advance Javascript Tutorials | Lesson 08
Javascript Objects | Beginner to Advance Javascript Tutorials | Lesson 08
🚀 JavaScript Array Methods Cheat Sheet ⚡ If you're learning JavaScript, mastering array methods will make your code cleaner, shorter, and more powerful. 📌 Essential methods every developer should know: ✅ map() ✅ filter() ✅ reduce() ✅ find() ✅ some() ✅ every() ✅ sort() ✅ slice() ✅ splice() These methods are asked in: 💼 Interviews 🧩 DSA ⚛️ React Projects 🌐 Real-world Web Development 💾 Save this cheat sheet for quick revision. 📤 Share it with a friend learning JavaScript. 💬 Which array metho... World Web, Learn Javascript, Cheat Sheets, Web Development, Coding, Make It Yourself
🚀 JavaScript Array Methods Cheat Sheet ⚡ If you're learning JavaScript, mastering array methods will make your code cleaner, shorter, and more powerful. 📌 Essential methods every developer should know: ✅ map() ✅ filter() ✅ reduce() ✅ find() ✅ some() ✅ every() ✅ sort() ✅ slice() ✅ splice() These methods are asked in: 💼 Interviews 🧩 DSA ⚛️ React Projects 🌐 Real-world Web Development 💾 Save this cheat sheet for quick revision. 📤 Share it with a friend learning JavaScript. 💬 Which array metho... World Web, Learn Javascript, Cheat Sheets, Web Development, Coding, Make It Yourself
🚀 Day 1/365 – JavaScript Array Methods 🔥 Starting my #365DaysOfCode infographic series! If you're learning JavaScript, mastering Array Methods is a game changer. These methods will help you write cleaner, shorter, and more efficient code. 📌 In this cheat sheet you'll learn: ✅ map() ✅ filter() ✅ reduce() ✅ find() ✅ findIndex() ✅ some() ✅ every() ✅ includes() ✅ sort() ✅ forEach() 💡 Whether you're preparing for interviews or building projects, you'll use these methods almost every day. 📥 S... Learn Javascript, Cheat Sheets, Game Changer, Map, Writing, Coding
🚀 Day 1/365 – JavaScript Array Methods 🔥 Starting my #365DaysOfCode infographic series! If you're learning JavaScript, mastering Array Methods is a game changer. These methods will help you write cleaner, shorter, and more efficient code. 📌 In this cheat sheet you'll learn: ✅ map() ✅ filter() ✅ reduce() ✅ find() ✅ findIndex() ✅ some() ✅ every() ✅ includes() ✅ sort() ✅ forEach() 💡 Whether you're preparing for interviews or building projects, you'll use these methods almost every day. 📥 S... Learn Javascript, Cheat Sheets, Game Changer, Map, Writing, Coding
Javascript manipulando arrays... . . . . #Javascriptarraymethods #array #arraymethods #manipulandoarrays How To Learn Javascript Arrays, Javascript Array Basics, Javascript Array Methods Tutorial, How To Create Arrays In Javascript, Javascript Array Addition Examples, Javascript Array Unique Function Code, Understanding Javascript Arrays, Javascript Array Types Infographic, How To Append To Javascript Array
Javascript manipulando arrays... . . . . #Javascriptarraymethods #array #arraymethods #manipulandoarrays How To Learn Javascript Arrays, Javascript Array Basics, Javascript Array Methods Tutorial, How To Create Arrays In Javascript, Javascript Array Addition Examples, Javascript Array Unique Function Code, Understanding Javascript Arrays, Javascript Array Types Infographic, How To Append To Javascript Array
JavaScript Array Methods Cheat Sheet for Beginners
JavaScript Array Methods Cheat Sheet for Beginners
a poster with the words and numbers in purple, white and yellow on it's side
a poster with the words and numbers in purple, white and yellow on it's side

Example: Removing a Book (ECMAScript 2022)

Here's how you might implement this in practice:

const books = [ { title: 'To Kill a Mockingbird', author: 'Harper Lee', publishedDate: '1960-07-11' }, { title: '1984', author: 'George Orwell', publishedDate: '1949-06-08' }, { title: 'The Great Gatsby', author: 'F. Scott Fitzgerald', publishedDate: '1925-04-10' } ]; const removeBook = (books, title) => { if (books.some((book, index) => { if (book.title === title) { delete books[index]; return true; } })) { return books.filter(book => book !== null); } return books; }; console.log(removeBook(books, 'The Great Gatsby'));

AD

The output will be the original 'books' array minus the 'The Great Gatsby' object.

In both methods, we manage to remove the target object from the array using its property value. However, the modern method provides a performance improvement, thanks to ECMAScript 2022 innovations. As always, keep an eye on the JavaScript ecosystem for new and improved ways to tackle common problems like this one.

AD