- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
How to get a subset of JavaScript object's properties?
Let’s say the following is our object −
var details ={ firstName: "John", lastName: "Smith", age:21, subjectName:"JavaScript", marks:89, coutryName:"US", collegeName:"MIT", passoutYear:2018 };
Following is the code to fetch only a subset −
Example
var details ={ firstName: "John", lastName: "Smith", age:21, subjectName:"JavaScript", marks:89, coutryName:"US", collegeName:"MIT", passoutYear:2018 }; var selectedFieldFromObjectDetails = (({ firstName, subjectName,marks,passoutYear }) => ({ firstName, subjectName,marks,passoutYear }))(details); console.log(selectedFieldFromObjectDetails);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo120.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo120.js{ firstName: 'John', subjectName: 'JavaScript', marks: 89, passoutYear: 2018 }
- Related Articles
- How to get a subset of a javascript object's properties?
- How to create a new object with only a subset of properties using vanilla Javascript
- How to iterate a JavaScript object's properties using jQuery?
- How to modify properties of a nested object in JavaScript?
- How to get only first word of object's value – JavaScript?
- How to duplicate Javascript object properties in another object?
- How to create object properties in JavaScript?
- How to delete object properties in JavaScript?
- JavaScript Object Properties
- How to get the properties of a picked object in mplot3d (matplotlib + python)?
- How to add, access, delete, JavaScript object properties?
- Filter the properties of an object based on an array and get the filtered object JavaScript
- How to get the size of a json object in JavaScript?
- How to construct a JSON object from a subset of another JSON object in Java?
- How to add properties and methods to an object in JavaScript?

Advertisements