How to truncate a string in JavaScript

In this tutorial, let’s look at how to truncate a string in JavaScript. We’re going to be looking at using the ‘slice’, ‘splice’, ‘split’ and other pre-defined functions in JavaScript, as well as manual methods using the ‘for’ loop. Let’s get to it then! Check if the string is already within the limit Before we … Read more

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

How to disable text selection using CSS?

In this tutorial, let’s look at the different ways to disable text selection in a web page using CSS properties. We’re going to first look at disabling/enabling text selection, and then we’re going to specifically look at disabling highlighting while keeping text selection active. Let’s get to it then! When would you need to disable … Read more