Enfield-LiE
Reactiflux5y ago
7 replies
Enfield-Li

JS decreasing

I have a js question, just can't figure out 😵‍💫 , can someone help me understand the code, why can we decrease the object value right away?

Code here:
function checkItem(arr) {
let obj = { a: 1, b: 1, c: 1 };

for (let i = 0; i < arr.length; i++) {
let char = arr[i];

if (!obj[char]) {
return false;
} else {
// obj[char] - 1; // ⬅ How does it work?
}
}

return true;
}

let arr = ["a", "b", "c"];
console.log(checkItem(arr));

(PS: the function is for checking if the value in arr existing in an object with the right amount)
Was this page helpful?