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

JavaScript string endsWith

In this tutorial, let’s look at how to use the String endsWith method in JavaScript. This method can be used to check whether the string ends with a given substring/string/character, and based on the result, you can assign if else or switch case statements that manipulate the program/data as you see fit. Introduction to the … Read more