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 check for “undefined” in JavaScript?
- How to make history.back() without getting a warning on the browser to reload the page?
- Split string into array
- convert Hsl to rgb and hex
- What does jQuery.fn mean?
- “Uncaught TypeError: Cannot read property ‘style’ of null at.. “
- Difference between document.referrer and window.parent.location.href
- JavaScript replace/regex
- What is the difference between state and props in React?
- Unable to resolve dependency tree error when installing npm packages
- Regex for password must contain at least eight characters, at least one number and both lower and uppercase letters and special characters
- OnChange event using React JS for drop down
- how to get the last character of a string?
- Set timeout for ajax (jQuery)
- Escaping Discord subset of markdown
- How to handle ETIMEDOUT error?
- bootstrap-datetimepicker for bootstrap 4
- Proper way to wait for one function to finish before continuing?
- Repository is not clean. Please commit or stash any changes before updating In Angular 8
- Bootstrap 4 Dropdown Menu not working?
- document.getElementsByClassName().innerHTML always returns “undefined”
- Bower: ENOGIT Git is not installed or not in the PATH
- JQuery get all elements by class name
- SyntaxError: expected expression, got ‘<'
- Attaching ‘onclick’ event to D3 chart background
- No provider for HttpClient
- The preferred way of creating a new element with jQuery
- How to pass parameters using ui-sref in ui-router to controller
- How to make an HTML back link?
- How to fix getImageData() error The canvas has been tainted by cross-origin data?
- How to make fadeOut effect with pure JavaScript
- Write / add data in JSON file using Node.js
- Set scroll position
- .filter is not a function
- What does wp-embed.min.js do in WordPress 4.4?
- Gutenberg extend blocks add new class name
- Rest API authentication issue when called from fetch request in bundle.js
- Listbox return wrong value in WordPress 3.9
- Logout user and delete cookies from the client side?
- wp_enqueue_script & constants?
- Where to upload JavaScript file in WordPress
- Can I alter the block editor’s paste text behavior?
- Custom Block – save.js function not saving attributes
- Issues trying to get an element by id
- How do I know if I should enqueue JS code or just include it in ONE PHP function?
- How to set javascript options for select2 in PHP array of plugin
- Change background video when scrolling reaches a certain ID
- Dynamically changing logo on scroll function [closed]
- Script not working in post content
- How could I add load more posts to my theme? [closed]
- Javascript button to call custom fields data