- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Concatenate two arrays of objects and remove repeated data from an attribute in JavaScript?
For this, use map() along with find(). Following is the code −
Example
var details1 = [ { productDetails: { isSold: true, productId:101 } }, { productDetails: { isSold: true, productId:103 } } ] var details2 = [ { productDetails: { isSold: false, productId:101 } } ] var details3 = details1.map(details1Object=>{ var newObject= details2.find(obj=>obj.productDetails.productId === details1Object.productDetails.productId) return newObject? newObject : details1Object }) console.log(details3)
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo183.js.
Output
This will produce the following output −
PS C:\Users\Amit\javascript-code> node demo183.js [ { productDetails: { isSold: false, productId: 101 } }, { productDetails: { isSold: true, productId: 103 } } ]
- Related Articles
- Adding two arrays of objects with existing and repeated members of two JavaScript arrays replacing the repeated ones
- JavaScript: create an array of JSON objects from linking two arrays
- How to concatenate two JavaScript objects with plain JavaScript ?
- How to combine two arrays into an array of objects in JavaScript?
- Extract arrays separately from array of Objects in JavaScript
- How to remove all blank objects from an Object in JavaScript?
- Sum arrays repeated value - JavaScript
- Sum JavaScript arrays repeated value
- The best way to remove duplicates from an array of objects in JavaScript?
- Remove duplicates from a array of objects JavaScript
- How to concatenate Two Arrays in C#?
- How to concatenate two arrays in java?
- Java Program to Concatenate Two Arrays
- Convert array of objects to an object of arrays in JavaScript
- Java Program to Remove Repeated Element from An ArrayList

Advertisements