Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js reduce break

[ 1, 2, 3, 4, 5].reduce((sum, el, _, arr) => {
  if (el === 4) {
    arr.length = 0;//Array passed to callback is now empty

    return sum;
  }

  return sum + el;
}); // return 1 + 2 + 3 = 6
 
PREVIOUS NEXT
Tagged: #js #reduce #break
ADD COMMENT
Topic
Name
7+7 =