How to assign multiple values to a JavaScript object?
With ES6 Spread Operator:
someVar = {...someVar, color: "blue", font_size: "30px"}
With ES2015 you can use Object.assign
:
const someVar = {
color: "white",
font_size: "30px",
font_weight: "normal"
};
const newVar = Object.assign({}, someVar, {
color: "blue",
font_size: "30px"});
console.log(newVar);
=>
{
color: "blue",
font_size: "30px",
font_weight: "normal"
}