Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const object1 = {name: 'Tu', hobbies: 'coding'}
- createNewObjectWithES6 = (prevObj, key, value) => {
- return {
- ...prevObj,
- [key]: value
- }
- }
- console.log(createNewObjectWithES6(object1, 'age', 31))
- // { name: 'Tu', hobbies: 'coding', age: 31 }
Add Comment
Please, Sign In to add comment