How to stop infinite loop JavaScript

In this tutorial, let’s learn all about different loops, how they occur, how to stop them once they occur, but also how to prevent them from occurring altogether. What are infinite loops? As the name implies, infinite loops are loops that run with no end. The most used loops are the ‘for’ and ‘while’ loops, … Read more

How to empty an array in JavaScript

In this tutorial, we’ll be looking at the different ways to empty an array in JavaScript. We’ll look at manipulating the length, assigning empty arrays to the original array, using various other pre-defined array methods, and looping through the array. Set the array’s length to 0 One of the easiest ways to reset an array … Read more

Get last element of array JavaScript

In this tutorial, let’s look at how to get the last element of an array in JavaScript. We’re going to start with the simplest method of extracting the last element by just accessing it using its index. Then, we’re going to move on to pre-defined methods like slice, splice, at and so on. Finally, let’s … Read more

How to disable a button in JavaScript?

In this tutorial, we’ll look at how to disable a button in JavaScript. We’ll be looking at 1. How to retrieve the button element in JavaScript, 2. Then 2 different ways to disable it from within your script file, 3. How to conditionally disable a button and finally, 4. How to toggle between enabled and … Read more

JavaScript repeat string

In this tutorial, we’re going to figure out ways to repeat the same string ‘n’ number of times, where n is a positive whole number. ES6 repeat() method The easiest way of doing this is by using the repeat() method, which is a pre-defined method in JavaScript. Introduction In the example below, I’ve created a … Read more