Skip to content

Instantly share code, notes, and snippets.

View blarfoon's full-sized avatar
💻
Coding

Davide blarfoon

💻
Coding
View GitHub Profile
const myObject = {
hi: "mom",
hello: "world",
};
const keys = Object.getOwnPropertyNames(myObject);
keys.forEach((key) => {
const value = myObject[k];
console.log(k, value);
const myObject = {
hi: "mom",
hello: "world",
};
const keys = Object.keys(myObject);
keys.forEach((key) => {
const value = myObject[k];
console.log(k, value);
const myObject = {
hi: "mom",
hello: "world",
}
for (const k in myObject) {
if(myObject.hasOwnProperty(k)) {
const value = myObject[k];
console.log(k, value);
}
const myObject = {
hi: "mom",
};
console.log(myObject.hi);
// Or
console.log(myObject["hi"]);
const myObject = {}; // or new Object()
myObject.hi = "mom";
// Or
myObject["hi"] = "mom";
// Or
const myObject = {
hi: "mom",
}
const myFirstObject = {};
const mySecondObject = myFirstObject;
mySecondObject.hi = "mom";
console.log(myFirstObject); // > {hi: "mom"}
console.log(mySecondObject); // > {hi: "mom"}
console.log(myFirstObject === mySecondObject); // > true
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])) {
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;
}
const myFirstObj = {};
const mySecondObj = {};
console.log(myFirstObj == mySecondObj, myFirstObj === mySecondObj); // > false false