

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Shortest syntax to assign properties from function call to an existing object in JavaScript
For this, use the following −
{... anyObjectName1,...anyObjectName2}.
Example
Following is the code −
function getTheObject() { return { lastName: "Smith", countryName:"US" } } var availableObj = { firstName: "Adam" } availableObj = { ...availableObj, ...getTheObject() }; console.log(availableObj);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo313.js.
Output
This will produce the following output −
PS C:\Users\Amit\javascript-code> node demo313.js { firstName: 'Adam', lastName: 'Smith', countryName: 'US' }
- Related Questions & Answers
- How to add properties and methods to an existing object in JavaScript?
- Extract properties from an object in JavaScript
- Remove number properties from an object JavaScript
- How to call a JavaScript function from an onClick event?
- How to call a JavaScript function from an onsubmit event?
- How to call a JavaScript function from an onmouseover event?
- How to call a JavaScript function from an onmouseout event?
- How to call an existing function in a database using JDBC API?
- How to return an object from a JavaScript function?
- How to call a JavaScript function from C++?
- How to remove a function from an object in JavaScript?
- How to call a parent window function from an iframe using JavaScript?
- How to call JavaScript function in an alert box?
- JavaScript Object Properties
- How to add properties and methods to an object in JavaScript?
Advertisements