Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function addPropertyToNewObject(obj, key, value) {
- const newObject = Object.assign({}, obj);
- newObject[key] = value;
- return newObject;
- }
- const myObj = {
- one: 1,
- two: 2,
- three: 3
- };
- const newObject = addPropertyToNewObject(myObj, 'four', 4);
- console.log(newObject);
- console.log(myObj);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement