Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do i compare a [null] list?

I have a list which is returning [null] but I want to replace that with []

I’m using useEffect() but I’m literally not able to find an expression that returns true when compared with null.

I’ve tried:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

listToCompare === null // false
listToCompare[0] === null // false
listToCompare === undefined // false
listToCompare === [null] // error even before compiling

This is irritating because [null] returns .length as 1 when I need it to be 0.

Can someone help me find an expression to return true when compared to [null]

Really confused on what a [null] list even is 🙁

>Solution :

You could try

const listToCompare = [null];
const isNull = !listToCompare.filter(Boolean).length

console.log(isNull) // returns true
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading