Last active
October 30, 2020 18:12
-
-
Save simonjcarr/a829968227c401ebc7b29bf4facc1f6b to your computer and use it in GitHub Desktop.
javascript_objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let objA = { a: 1, b: 2, c: 3 } | |
let objB = { a: "X", d: "Y" } | |
let objC = Object.assign(objA, objB) | |
console.log("objA:- ", objA) | |
console.log('objB:- ', objB); | |
console.log('objC:- ', objC); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const messageObj = { | |
printMessage: function () { | |
console.log(`The message: is ${this.message}`) | |
} | |
} | |
newObj = Object.create(messageObj) | |
newObj.message = "Hello World!" | |
newObj.printMessage() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let obj = { | |
a: 1, | |
b: 2, | |
c: 3, | |
messages: { | |
message1: "1233", | |
message2: { | |
detail: "Hello" | |
} | |
} | |
} | |
console.log(Object.entries(obj)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let obj = { | |
a: 1, | |
b: 2, | |
c: 3, | |
address: { | |
line1: '1 street', | |
postcode: 'XXX XXX', | |
}, | |
}; | |
console.log(Object.entries()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let obj = { | |
a: 1, | |
b: 2, | |
c: 3 | |
} | |
Object.freeze(obj) | |
obj.a = 4 | |
obj.d = 5 | |
delete obj.c | |
console.log(obj) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment