copy an object with object.assign
// We want to update status property value to 'online'
const data = {
user: 'CamperBot',
status: 'offline',
friends: '732,982',
};
// Object.assign takes in a target object (1st parameter) and source objects
// (rest of the parameter list). Source object properties are mapped to the
// target object (which is usually empty). Any matching properties are
// overwritten by the source objects
const newObject = Object.assign({}, data, {status: 'online'})
console.log(newObject)
/*
{
user: 'CamperBot',
status: 'online',
friends: '732,982',
}
*/
Also in JavaScript:
- local storage javascript
- js validate email
- json boolean
- disable input angular
- short string javascript
- javascript radio button value if checked
- js get all select options
- how to generate a random salt in nodejs
- click binding angular 8
- js detect screen size change
- get header height jquery
- js .substring
- next js protected routes
- immediately invoked function expression
- send event to child component angular
- javascript array add
- react on hover reveal
- numbers counting up css
- build an api in nodejs using express to send emails using the gmail rest api without client libraries
- how to check if a string contains numbers in javascript
- how to use online mysql database with node js
- ajax latest version
- javascript create json object from array
- javascript remove all spaces from string