filter(Boolean)

sudyn·2023년 12월 4일

JavaScript

목록 보기
13/14

배열을 믿을 수 있는 상태로 만드는 것

Boolean 값을 iterator로 사용해 제거할 수 있음
false, 0, -0, on, "", null, undefined, NaN

let array = [false, 0, -0, 0n, "", null, undefined, NaN, {hello: "world"}];

console.log(array.filter(Boolean)); // [{hello: "world"}]

참고
https://michaeluloth.com/javascript-filter-boolean/

profile
개발계발하는 프론트엔드 개발자🍠

0개의 댓글