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 myObject = { | |
hi: "mom", | |
hello: "world", | |
}; | |
const keys = Object.getOwnPropertyNames(myObject); | |
keys.forEach((key) => { | |
const value = myObject[k]; | |
console.log(k, value); |
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 myObject = { | |
hi: "mom", | |
hello: "world", | |
}; | |
const keys = Object.keys(myObject); | |
keys.forEach((key) => { | |
const value = myObject[k]; | |
console.log(k, value); |
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 myObject = { | |
hi: "mom", | |
hello: "world", | |
} | |
for (const k in myObject) { | |
if(myObject.hasOwnProperty(k)) { | |
const value = myObject[k]; | |
console.log(k, value); | |
} |
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 myObject = { | |
hi: "mom", | |
}; | |
console.log(myObject.hi); | |
// Or | |
console.log(myObject["hi"]); |
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 myObject = {}; // or new Object() | |
myObject.hi = "mom"; | |
// Or | |
myObject["hi"] = "mom"; | |
// Or |
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 myObject = { | |
hi: "mom", | |
} |
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 myFirstObject = {}; | |
const mySecondObject = myFirstObject; | |
mySecondObject.hi = "mom"; | |
console.log(myFirstObject); // > {hi: "mom"} | |
console.log(mySecondObject); // > {hi: "mom"} | |
console.log(myFirstObject === mySecondObject); // > true |
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
function areEqualDeep(a, b) { | |
if (typeof a == "object" && a != null && typeof b == "object" && b != null) { | |
const count = [0, 0]; | |
for (const key in a) count[0]++; | |
for (const key in b) count[1]++; | |
if (count[0] - count[1] != 0) { | |
return false; | |
} | |
for (const key in a) { | |
if (!(key in b) || !areEqualDeep(a[key], b[key])) { |
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
function areEqualShallow(a, b) { | |
for (const key in a) { | |
if (!(key in b) || a[key] !== b[key]) { | |
return false; | |
} | |
} | |
for (const key in b) { | |
if (!(key in a) || a[key] !== b[key]) { | |
return false; | |
} |
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 myFirstObj = {}; | |
const mySecondObj = {}; | |
console.log(myFirstObj == mySecondObj, myFirstObj === mySecondObj); // > false false |