I have this kind of object
I want to get new object with keys that have "exist === true"
const someObj = {
super: {
exist: true
},
photo: {
exist: true
},
request: {
exist: false
}
}
const newObj = Object.entries(someObj).reduce((newObj, [key, val]) => {
if (this.key.exist) { // how to check "exist" is true ?
return { ...newObj, [key]: val }
}
}, {});
console.log(newObj);
You can be achieve your required result by following code
DEMO
const someObj = {
super: {
exist: true
},
photo: {
exist: true
},
request: {
exist: false
}
};
const newObj = Object.entries(someObj).reduce((newObj, [key, val]) => {
if (val.exist) {
newObj[key] = val;
}
return newObj;
}, {})
console.log(newObj);
.as-console-wrapper { max-height: 100% !important; top: 0;}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With