I have an empty array called objToArray. I'm trying to use a for-in-loop to fill the array with all of the numbers from a hash checkObj object, if the keys have a value greater than or equal to 2.
const checkObj = {
oddNum: 1,
evenNum: 2,
foundNum: 5,
randomNum: 18
};
const objToArray = [];
for (let values in checkObj) {
if (Object.values(checkObj) >=2 ) {
objToArray.push(checkObj.values())
}
}
console.log(objToArray);
So far, I get objToArray as an empty array even though it should contain three elements and should equal [2, 5, 18].
Object.values(checkObj) >=2withcheckObj[values] >= 2andobjToArray.push(checkObj.values())withobjToArray.push(checkObj[values]).checkObjyou can accessoddNumproperty value withcheckObj.oddNumorcheckObj["oddNum"]or forlet key = "oddNum";checkObj[key]will return same value.