Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript custom repeat function

/* Build a custom repeat function: perform an action "n" times. */

repeat = (n, action) => {
  for (let i = 0; i < n; i++) {
    action(i);
  }
}

repeat(5, n => {
  console.log(2 * n);
});
// → 0 2 4 6 8
Comment

repeat a function javascript

setInterval(function(){
  console.log("Hello");
  console.log("World");
}, 2000); //repeat every 2s
Comment

javascript repeat function

/* The string.repeat(n) method constructs and returns a new string
with "n" number of copies. */

const chorus = "Because I'm happy. ";
console.log(`Chorus lyrics: ${chorus.repeat(3)}`);
// → "Chorus lyrics: Because I'm happy. Because I'm happy. Because I'm happy. "

// Use within a function
greeting = (n, words) => words.repeat(n);
console.log(greeting(5, "howdy ")); 
// → "howdy howdy howdy howdy howdy "
Comment

PREVIOUS NEXT
Code Example
Javascript :: alpine in laravel mix 
Javascript :: access to static file nodejs 
Javascript :: count number of duplicate pairs in array javascript 
Javascript :: jquery select option by text 
Javascript :: array reverse algorithm in js 
Javascript :: convert string in ethers.js 
Javascript :: jquery get name attribute 
Javascript :: on focus jquery 
Javascript :: how to make a textarea unwritable in react native 
Javascript :: insert item into array specific index javascript 
Javascript :: javascript cahnge colour of strokerect 
Javascript :: js reverse nested array 
Javascript :: add date in javascript 
Javascript :: vue 3 computed getter setter 
Javascript :: how to get selected value of dynamically created dropdown in jquery 
Javascript :: send form data using fetch 
Javascript :: react-router-dom navlink active 
Javascript :: lodash toLower 
Javascript :: jquery on click function 
Javascript :: js navigate to anchor 
Javascript :: factorial in javascript 
Javascript :: jquery serialize with file upload 
Javascript :: angular 9 form value changes 
Javascript :: js get html input range value 
Javascript :: get date js 
Javascript :: how to use url parameters in react 
Javascript :: how to add two attay into object in javascript 
Javascript :: make first letter capital 
Javascript :: JavaScript Window - The Browser Object Model 
Javascript :: Package path ./compat is not exported from 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =