उदाहरण
filter() का उपयोग करके नल, अनडिफाइंड और खाली स्ट्रिंग हटाएं।
var names = [null, "John", null, "David", "", "Mike", null, undefined, "Bob", "Adam", null, null];
console.log("Before filter null=");
console.log(names);
var filterNullValues = names.filter(obj => obj);
console.log("After filtering the null values=");
console.log(filterNullValues);
प्रोग्राम चलाने के लिए:
node fileName.js
आउटपुट
PS C:\Users\Amit\JavaScript-code> node demo148.js Before filter null=[ null, 'John', null, 'David', '', 'Mike', null, undefined, 'Bob', 'Adam', null, null ] After filtering the null values= [ 'John', 'David', 'Mike', 'Bob', 'Adam' ]