Answers for "js immutability"

0

js immutability

const userProfile = {
  username: 'Jack',
  email: 'Jack@email',
  socialMedia: {
    twitter: '@jack',
    facebook: 'jackm',
    linkedIn: 'jackmay',
  },
}
const newUserProfile = {
  ...userProfile,
  email: 'JackNew@email',
  socialMedia: { ...userProfile.socialMedia, twitter: '@newTwitter' },
}
// const newUserProfile = JSON.parse(JSON.stringify(userProfile))
console.log('orginal', userProfile)
console.log('new', newUserProfile)
Posted by: Guest on April-27-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language