The new spread syntax can be used to elegantly merge several objects in the following way:
const person = { name: 'David Walsh', gender: 'Male' };
const tools = { computer: 'Mac', editor: 'Atom' };
const summary = {...person, ...tools};
Is there a way to use this in a dynamical scenario, where the number and names of the objects to be merged are not known beforehand?
If
var objects_to_be_merged = get_objects();
generated an iterable list of objects during runtime, how can I use the spread operator iteratively to create a summary object like in the example above?
You can use Object.assign()
with spread syntax to merge array of objects.
const person = { name: 'David Walsh', gender: 'Male' };
const tools = { computer: 'Mac', editor: 'Atom' };
const objects = () => [person, tools];
const summary = Object.assign({}, ...objects());
console.log(summary)
I want to use the selector in document.querySelector() to select all a tags with the text "print". <a href="https://www.google.co.in">print</a> how can I select the same. I don't want to ...
I want to use the selector in document.querySelector() to select all a tags with the text "print". <a href="https://www.google.co.in">print</a> how can I select the same. I don't want to ...
I have a table and i created own scrollbar for iPad in my project. Now, the table is moving as the user touch and drag it, but how to move my scrollbar according to that table. I tried but for me ...
I have a table and i created own scrollbar for iPad in my project. Now, the table is moving as the user touch and drag it, but how to move my scrollbar according to that table. I tried but for me ...
I would like to see this column, I can see it here https://developers.google.com/web/fundamentals/performance/resource-prioritization But I can't see it inside my Chrome Dev tools's Network tab. My ...
I would like to see this column, I can see it here https://developers.google.com/web/fundamentals/performance/resource-prioritization But I can't see it inside my Chrome Dev tools's Network tab. My ...
I have a list of airports in XML format which I would like to use with jquery autocomplete. The XML file looks like this: <item code="AAR" airport="Aarhus" country="Denmark" /> When a ...
I have a list of airports in XML format which I would like to use with jquery autocomplete. The XML file looks like this: <item code="AAR" airport="Aarhus" country="Denmark" /> When a ...