1 |
const repeat = (func, times) => [...Array(times).keys()].map(func); |
JavaScript Tricks
Swapping 2 JS variables’ values in one line
1 2 3 |
let a = 10, b = 20; [a, b] = [b, a]; console.log(a, b); // => 20, 10 |
Handy JS in operator
The ‘in’ operator can help to check if an Array contains specified index or an Object contains a specified key …
Conditionally add a key to a JS Object or Array
Conditionally add a key to an object: …
Remove a key from a JS Object using Spread operator
Remove a key from an object with spread operator …
Nice tricks with Switch operator in JavaScript
Evaluating expressions inside Switch statement …