- 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
Finding content of arrays on the basis of specific property in JavaScript?
For this, you can use find() along with a map(). Let’s say we have student records with name, rollno and subject.
Example
var firstObject= [ { "FirstName": "David", "RollNo": "105", "Subject": "MongoDB" }, { "FirstName": "Mike", "RollNo": "110", "Subject": "JavaScript"} ]; var secondObject= [ { "FirstName": "Bob", "RollNo": "101", "Subject": "Java" }, { "FirstName": "John", "RollNo": "110", "Subject": "MySQL" } ]; var output = firstObject.map(first=>(secondObject.find(second=>second.RollNo==first.R ollNo) || first)); console.log(output);
To run the above program, you need to use the following command −
node fileName.js
Here, my file name is demo33.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo33.js [ { FirstName: 'David', RollNo: '105', Subject: 'MongoDB' }, { FirstName: 'John', RollNo: '110', Subject: 'MySQL' } ]
- Related Articles
- Grouping on the basis of object property JavaScript
- Array grouping on the basis of children object’s property in JavaScript
- Finding the inclination of arrays in JavaScript
- Finding the continuity of two arrays in JavaScript
- Finding the intersection of arrays of strings - JavaScript
- Finding intersection of arrays of intervals in JavaScript
- Finding intersection of multiple arrays - JavaScript
- Finding reversed index of elements in arrays - JavaScript
- Delete a specific record on the basis of EmployeeId in MySQL
- Finding the missing number between two arrays of literals in JavaScript
- Finding intersection of arrays that contain repetitive entries in JavaScript
- Finding Common Item Between Arbitrary Number of Arrays in JavaScript
- Grouping array of array on the basis of elements in JavaScript
- Determining rank on basis of marks in JavaScript
- Finding the difference between two arrays - JavaScript

Advertisements