
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to create a new object with only a subset of properties using vanilla Javascript
To get a subset of object's properties and create a new object out of those properties, use object destructuring and property shorthand. For example, You have the following object −
Example
const person = { name: 'John', age: 40, city: 'LA', school: 'High School' }
And you only want the name and age, you can create the new objects using −
const {name, age} = person; const selectedObj = {name, age}; console.log(selectedObj);
Output
This will give the output −
{ name: 'John', age: 40 }
- Related Articles
- How to get a subset of a javascript object's properties?
- How to get a subset of JavaScript object's properties?
- How to create object properties in JavaScript?
- How to create a new column with a subset of row sums in an R data frame?
- How to create a Number object using JavaScript?
- How to create a URL object using JavaScript?
- How to create a new img tag with JQuery, with the src and id from a JavaScript object?
- How to create a session only cookies with JavaScript?
- How to iterate a JavaScript object's properties using jQuery?
- How to create a new directory by using File object in Java?
- How to create a subset using character column with multiple matches in R?
- How to modify properties of a nested object in JavaScript?
- How to create JavaScript objects using new operator?
- How to subset a data.table object using a range of values in R?
- How to create an object and access its properties in JavaScript?

Advertisements