Changing an object

Changing an object is about changing properties on it as well as adding properties to it. First off, let's look at how to change existing values:

// core-concepts/object.js// the old waylet anakin = { name: "anakin" };anakin.name = "darth";console.log(anakin);// the Redux waylet anakinRedux = { name: "anakin" };let darth = Object.assign({}, anakinRedux, { name: "darth" });console.log(anakinRedux);console.log(darth);

That covers the existing case. What about adding a new property? We can do that like so:

// core-concepts/object-add.js// the old waylet anakin = { name: "anakin" };console.log("anakin", anakin);anakin["age"] = "17";console.log("anakin with age", anakin);// the Redux waylet anakinImmutable = { name: "anakin" ...

Get Architecting Angular Applications with Redux, RxJS, and NgRx now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.