Right now, if 'Everything' in the list is detected, the output becomes [""].
Expected output: []
Copy.names = rule.names.map(function(x) {
if (x.name ==='Everything') {
return '';
} else {
return x.name;
}
});
map() calls a function once for each element in an array. map() does not execute the function for empty elements.
A map key can hold the null value. Adding a map entry with a key that matches an existing key in the map overwrites the existing entry with that key with the new entry. Map keys of type String are case-sensitive. Two keys that differ only by the case are considered unique and have corresponding distinct Map entries.
Map.delete() Method in JavaScript The Map. delete() method in JavaScript is used to delete the specified element among all the elements which are present in the map.
Use Array.prototype.filter:
Copy.names = rule.names.filter(function(x) {
return x.name !=='Everything';
}).map(function (x) {
return x.name;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With