Menu

gitpiper

times javascript Code Snippet in 2024

functionintermediate

Last Updated: 23 July 2024

Iterates over a callback n times

  • Use Function.prototype.call() to call fn n times or until it returns false.
  • Omit the last argument, context, to use an undefined object (or the global object in non-strict mode).
const times = (n, fn, context = undefined) => { let i = 0; while (fn.call(context, i) !== false && ++i < n) {} };
var output = ''; times(5, i => (output += i)); console.log(output); // 01234

javascript snippet similar to times For You in July 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️