Scenario
We have two objects:
const o1 = {
foo: 'foo',
boo: 'boo'
}const o2 = {
pityTheFoo: 'pityTheFoo'
}
And we want all the keys and values inside a single object like this:
const o3 = {
foo: 'foo',
boo: 'boo',
pityTheFoo: 'pityTheFoo'
}
Approach
Use the destructuring
operator:
const o3 = {
...o1,
...o2
}