Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. function addPropertyToNewObject(obj, key, value) {
  2. const newObject = Object.assign({}, obj);
  3. newObject[key] = value;
  4. return newObject;
  5. }
  6.  
  7. const myObj = {
  8. one: 1,
  9. two: 2,
  10. three: 3
  11. };
  12.  
  13. const newObject = addPropertyToNewObject(myObj, 'four', 4);
  14.  
  15. console.log(newObject);
  16. console.log(myObj);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement