Comment appliquer la limite dans le filtre JavaScript
const arr = [1,0,2,0,3,0,4,5,6,7,8,9,10,11,12,13,14];
const filtered = arr.filter(function(item) {
if (this.count < 1 && item > 0) {
this.count++;
return true;
}
return false;
}, {count: 0});
console.log(filtered);
Run code snippetHide results
Rana Ahmer