
- 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
Combine objects and delete a property with JavaScript
We have the following array of objects that contains two objects and we are required to combine both objects into one and get rid of the chk property altogether −
const err = [ { "chk" : true, "name": "test" }, { "chk" :true, "post": "test" } ];
Step 1 − Combining objects to form a single object
const errObj = Object.assign(...err);
Step 2 − Removing the chk property
delete errObj['chk']; console.log(errObj);
Let us now see the entire code with output −
Example
const err = [ { "chk" : true, "name": "test" }, { "chk" :true, "post": "test" } ]; const errObj = Object.assign(...err); delete errObj['chk']; console.log(errObj);
Output
Output in the console will be −
{ name: 'test', post: 'test' }
- Related Articles
- Combine array of objects in JavaScript
- Group objects by property in JavaScript
- How to delete a property of an object in JavaScript?
- How to combine two arrays into an array of objects in JavaScript?
- How to iterate over objects in array and sum a property in JavaScript
- Filter array of objects by a specific property in JavaScript?
- Grouping objects based on key property in JavaScript
- How to create a delete confirmation modal with CSS and JavaScript?
- With JavaScript DOM delete rows in a table?
- Add property to common items in array and array of objects - JavaScript?
- Sorting an array of objects by property values - JavaScript
- Sort array of objects by string property value - JavaScript
- Sort array of objects by string property value in JavaScript
- Retrieve property value selectively from array of objects in JavaScript
- Update array of objects with JavaScript?

Advertisements