TechLivoasis
Simplifying Tech, Elevating Life
Search This Blog
2026/08/11
Javascript:Remove falsy values from array
Remove
falsy
values
in
array:
Code:
const
arr
=
[1,
0,
false
,
"hello",
"",
null,
undefined,
NaN,
5]
;
const
result
=
arr.filter
((
item
)
=
>
{
return
Boolean
(
item
)
});
console.log(result
);
Output:
[ 1,
'hello'
,
5
]
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment