Guest User

Untitled

a guest
Nov 20th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. const object1 = {name: 'Tu', hobbies: 'coding'}
  2.  
  3. copyAndCreateNewObject = (prevObj, key, value) => {
  4. const obj = {}
  5. for (let k in prevObj) {
  6. obj[k] = prevObj[k]
  7. }
  8. obj[key] = value
  9. return obj
  10. }
  11.  
  12. console.log(copyAndCreateNewObject(object1, 'age', 31))
  13. // { name: 'Tu', hobbies: 'coding', age: 31 }
Add Comment
Please, Sign In to add comment