
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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' }
Advertisements