DEV Community

Discussion on: 1 line of code: How to clean an Array

Collapse
 
pengeszikra profile image
Peter Vivo

Why we would like "" from string list? "" and 0 is give false result but each means something.

[[], {}, null, undefined, "", 0, NaN, -0, Infinity]
  .filter(item => (item ?? null) !== null)
Enter fullscreen mode Exit fullscreen mode
Collapse
 
martinkr profile image
Martin Krause

Hi Peter,

I can not exactly follow you train of thought. Would you mind to elaborate a bit?

Thank you !

Collapse
 
grendel profile image
grendel

Empty string is something, not nothing. This kind of thinking is paramount in, for example, shell scripting/programming, where whether a string is null or simply doesn't exist changes everything about the command