Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to apply limit in filter 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
Comment

PREVIOUS NEXT
Code Example
Javascript :: Dart regex all matches 
Javascript :: javascript promise 
Javascript :: Web Geolocation API 
Javascript :: export multiple functions react 
Javascript :: jquery change the label of a value in select 
Javascript :: js array.splice first element 
Javascript :: react router active link css 
Javascript :: detect invalid date js 
Javascript :: angular capitalize pipe 
Javascript :: how to make a preloader dissapear in html 
Javascript :: the sum of all first n natural numbers js 
Javascript :: jquery add class to body 
Javascript :: jquery find element before 
Javascript :: usecontext hook react 
Javascript :: javascript get width 
Javascript :: on window resize and on page load 
Javascript :: js array 0 to n 
Javascript :: what is the function of delete operator in javascript 
Javascript :: object destructuring 
Javascript :: usecallback 
Javascript :: queryselectorall example 
Javascript :: js tofixed 
Javascript :: parse json c# 
Javascript :: why to use event.persist 
Javascript :: storage package npm react 
Javascript :: Change the text inside the <p tag: 
Javascript :: mongoose updateone example 
Javascript :: js in_array 
Javascript :: onpress setstate react native 
Javascript :: javascript .firstordefault 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =