Take While

Take elements from the start of an array while a condition is true.

Code

General
const idx = arr.findIndex(x => x >= threshold);
return idx === -1 ? arr : arr.slice(0, idx);

Parameters

Array

Take while less than threshold

Browser·fetch() may be limited by CORS

More JavaScript Snippets