const droid = {
name: 'R2-D2',
height: '1.08'
}
// insted of define a new object with reference, we pass a spread operator of the original object
const newDroid = {
...droid,
colors: ['blue', 'silver', 'white'],
productionInformation: {
manufacturer: 'Industrial Automaton',
productLine: 'R-series',
model: 'R2 series astromech droid'
}
}
//the original object is not updated
console.log(droid)
// [object Object] {
// height: '1.08',
// name: 'R2-D2'
// }
// we created a new object with the new attributes
console.log(newDroid)
// [object Object] {
// colors: ['blue', 'silver', 'white'],
// height: '1.08',
// name: 'R2-D2',
// productionInformation: [object Object] {
// manufacturer: 'Industrial Automaton',
// model: 'R2 series astromech droid',
// productLine: 'R-series'
// }
// }
Created
March 20, 2021 13:25
-
-
Save darleykrefta/c4204ada73d022df4c49029293d7e0b4 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment