You can use IIFE (Immediately Invoked Function Expression) and function recursion instead. Like this:
let i = 0; (function repeat(){ if (++i > 5) return; setTimeout(function(){ console.log("Iteration: " + i); repeat(); }, 5000); })();
Live fiddle here.
Related Posts:
- Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’
- Angular: mat-form-field must contain a MatFormFieldControl
- (change) vs (ngModelChange) in angular
- Angular ForEach in Angular4/Typescript?
- Angular4 – No value accessor for form control
- npm WARN … requires a peer of … but none is installed. You must install peer dependencies yourself
- What is ViewChild in Angular2?
- How do I download a file with Angular2 or greater
- Angular 2 Sort table columns
- How do I install Angular 2 using NPM?
- What is TypeScript and why would I use it in place of JavaScript? [closed]
- ES6 Map in Typescript
- Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’
- Angular: conditional class with *ngClass
- How to define type for a function callback (as any function type, not universal any) used in a method parameter
- TypeScript foreach return [duplicate]
- TypeScript React.FC
confusion - What is an unhandled promise rejection?
- How to perform string interpolation in TypeScript?
- Typescript : Property does not exist on type ‘object’
- Cannot find module ‘@angular-devkit/core’
- No value accessor for form control
- Angular: Error no directive with “exportAs” set to “ngForm”
- Angular 4 setting selected option in Dropdown
- Angular: conditional class with *ngClass
- Possible to extend types in Typescript?
- No overload matches this call. Type ‘string’ is not assignable to type ‘Signals’
- RegExp in TypeScript
- How do you format a Date/Time in TypeScript?
- Angular: conditional class with *ngClass
- How do I check whether an array contains a string in TypeScript?
- Module not found: Error: Can’t resolve ‘fs’ in
- Uncaught ReferenceError: define is not defined typescript
- Angular 2 – Using ‘this’ inside setTimeout
- How to fix Cannot find module ‘typescript’ in Angular 4?
- String.Format not work in TypeScript
- declaration or statement expected javascript/typescript
- TypeError: Class extends value undefined is not a function or null
- Can’t perform a React state update on an unmounted component
- How to set Angular 4 background image?
- SyntaxError: Unexpected token C in JSON at position 0 – Ionic 2 Http GET request
- Crop the image using JavaScript
- What does the .subscribe() function do?
- Angular 2 Hover event
- What are differences between SystemJS and Webpack?
- typescript – cloning object
- How to use forEach loop correctly in angular 2?
- How to use onBlur event on Angular2?
- Using Angular 2 without TypeScript Transpiler
- How can I generate a rainbow circle using HTML5 canvas?
- What’s the difference between “{}” and “[]” while declaring a JavaScript array?
- What does “javascript:void(0)” mean?
- For-each over an array in JavaScript
- How to delete a cookie?
- How do you use the ? : (conditional) operator in JavaScript?
- Which equals operator (== vs ===) should be used in JavaScript comparisons?
- are there dictionaries in javascript like python?
- How to do associative array/hashing in JavaScript
- How to make a discord bot create an invite for every server it joins?
- addEventListener vs onclick
- “Uncaught SyntaxError: Cannot use import statement outside a module” when importing ECMAScript 6
- How do I check if an array includes a value in JavaScript?
- JavaScript document.getElementById().value logs empty value
- How do I color a hexagonal grid such that it doesn’t have neighbors of the same color?
- How to format a JavaScript date
- What does href expression do?
- map function for objects (instead of arrays)
- Wait 5 seconds before executing next line
- Failed to load resource: the server responded with a status of 404 (Not Found)
- How to check whether a string contains a substring in JavaScript?
- Check if a string has a certain piece of text [duplicate]
- Kadane’s algorithm explained
- What is console.log?
- Dynamically creating charts of each row in an HTML table with chart.js
- Failed to load resource: the server responded with a status of 404 (Not Found)
- How to convert a string to an integer in JavaScript?
- Maximum call stack size exceeded error
- How to change CSS using jQuery?
- How to properly use jsPDF library
- How to reload a page using JavaScript
- How can I do string interpolation in JavaScript?
- Can I use complex HTML with Twitter Bootstrap’s Tooltip?
- Start script missing error when running npm start
- How do I redirect to another webpage?
- How to round to at most 2 decimal places, if necessary?
- What is VanillaJS?
- Invariant Violation: Objects are not valid as a React child
- How do I make the first letter of a string uppercase in JavaScript?
- How to handle Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause()
- window.location.href and window.open () methods in JavaScript
- Invariant Violation: Objects are not valid as a React child
- What’s the difference between using “let” and “var”?
- How do I make the first letter of a string uppercase in JavaScript?
- Loop through an array in JavaScript
- How to format a JavaScript date
- What does this symbol () => mean in Javascript? [duplicate]
- How do I redirect to another webpage?
- Google reCAPTCHA V3.0 not working. “ERROR for site owner: Invalid key type”
- How to round to at most 2 decimal places, if necessary?
- Google Chrome Uncaught (in promise) DOMException while playing AUDIO