Navneet
Navneet

Reputation: 47

I only need the 0 value in this case from an array of [0, undefined, null, false]

I have tried the filter and find method to get the value 0 but it did not worked it just returns undefined

[0, undefined, null, false].filter(e => e) // output empty array
[0, undefined, null, false].find(e => e)  // output undefined

If anybody helps me out to find the solution for this I would greatfull for you help

Upvotes: 1

Views: 47

Answers (1)

Amir MB
Amir MB

Reputation: 3418

const filtered = [0, undefined, null, false].filter(e => e === 0);
const found = [0, undefined, null, false].find(e => e === 0);

console.log(filtered);
console.log(found);

Upvotes: 1

Related Questions