Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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: #break
ADD COMMENT
Topic
Name
3+2 =