How to get values from an Array except undefined,null, and empty value

blossom0417
Jan 6, 2021

--

var ages = [32, 33, 16, undefined];

function checkAdult(age) {
return !!age;
}

function myFunction() {
document.getElementById(“demo”).innerHTML = ages.filter(checkAdult);
}

// 32, 33, 16

  • !!v 코드가 undefined, null, empty value, empty array 를 걸러낸다.
    empty object는 [object object]로 반환된다.

#ref

--

--

No responses yet