Found 10483 Articles for Web Development

How to convert a string into the lower case using JavaScript?

Shubham Vora
Updated on 08-Aug-2022 09:08:41

1K+ Views

This tutorial will teach us to convert the string into the lower case. Programmers can ask themselves why they need to convert the string in the lower case? Let’s understand the answer using the single example. Suppose you are developing the application and need to take input from the user using the form or either way. Users can type the text in upper case, lower case, or a mix of both. Also, you have stored some values in the lower case in your database, and you need to match them with the user input. If you match the input string ... Read More

How to convert a string into upper case using JavaScript?

Shubham Vora
Updated on 08-Aug-2022 09:10:25

2K+ Views

This tutorial will teach us to convert the string into the upper case. In many governments, websites users have seen while filling forms, characters are automatically converted into the upper case to avoid any mistakes. It needs to do because JavaScript is a case-sensitive language, and if the user adds some characters in lower case and some in upper case, it can mismatch with the string stored in the database. To get accurate data from the user, it is needful to convert the string to uppercase. Here, we will learn the different methods to convert the string into the upper ... Read More

What is the difference between substr() and substring() in JavaScript?

Alankritha Ammu
Updated on 15-Jun-2020 06:46:04

426 Views

The examples given above have the same output, but yes the method differs, with that the parameters too.The substring() method the second parameter is the index to stop the search, whereas the second parameter of substr() is the maximum length to return.ExampleLet’s see an example for substr() method in JavaScript −Live Demo           JavaScript String substr() Method                          var str = "Apples are round, and apples are juicy.";          document.write("(1, 2): " + str.substr(1, 2));          document.write("(-2, 2): ... Read More

How to get the last index of an occurrence of the specified value in a string in JavaScript?

Shubham Vora
Updated on 20-Oct-2022 08:02:40

577 Views

In this tutorial, we will learn how to get the last index of an occurrence of the specified value in a string in JavaScript. The last index of an occurrence means the last position found of the searched item in a given string. It can be a single character or a word also. To find the index of the last occurrence, we have a method in JavaScript that is the lastIndexOf() method. Using the lastIndexOf() Method This method will search the whole string and return the index of that value's last position. If it doesn’t find the item, it ... Read More

How to initialize a boolean array in JavaScript?

Shubham Vora
Updated on 14-Sep-2022 13:47:32

4K+ Views

In this tutorial, we will learn how to initialize a boolean array in JavaScript. We can initialize a boolean array in JavaScript in three ways− Using the fill() Method Using the Array from() Method Using the for Loop Using the fill() Method We can initialize a boolean array using the fill() method. The fill() method sets the static value of all array elements from the beginning index to the end index. Syntax //initialization of boolean array with fill() method let arrayName = new Array(array_length).fill(true/false); In the above syntax, we create an array with the name "arrayName" ... Read More

How to check if a variable is boolean in JavaScript?

Shubham Vora
Updated on 08-Aug-2022 08:47:37

29K+ Views

In this tutorial, we will learn to check if the variable is a Boolean in JavaScript. In JavaScript, if we match the two different variables with the same value and different data types using the equality operator, it returns a true value. It means if we compare a twovariable with the true value but different data types such as Boolean and string, it will generate a positive result. To overcome these problems, we need to check if the variable is of type Boolean or not before matching it with other values. Users can use the three methods below to check ... Read More

How to declare a boolean in JavaScript?

Ayyan
Updated on 15-Jun-2020 06:24:05

2K+ Views

To declare a Boolean in JavaScript, you need to assign true or false value.var answer = true;ExampleTo learn about the working of Boolean, let’s see the following example −Live Demo           JavaScript Boolean                        var num1 = 10;          var num2 = 20;          document.write(num1 > num2);          

How to calculate the nth root of a number in JavaScript?

Saurabh Jaiswal
Updated on 06-Jan-2023 13:32:57

1K+ Views

We have given a number and the task is to calculate the nth root of that number using JavaScript. We have multiple ways to achieve this, some of which are the following. Using Math.pow() Method Using Logarithm To get the nth root of a number firstly let’s understand whose root we can calculate and which number’s root we cannot calculate. If the number is positive and the root is also even then we will get two solutions. E.g − 2nd root of 16 is +4 and -4, similarly 4th root of 16 is +2 and -2 If ... Read More

How to check whether a value is a number in JavaScript?

Shubham Vora
Updated on 14-Sep-2023 14:11:27

26K+ Views

In this tutorial, we will learn to check whether a value is a number in JavaScript. In JavaScript, it is necessary to check the variable's data type while performing some operation. Otherwise, it can create some unknown bugs in your application. For example, when users use the addition operator with the string, it concatenates the two strings, and in the same way, if users use the addition operator with a number, it adds two numbers. Now, think that the user wants to add two numbers but is concatenating the two strings. Here, we have three different methods to check whether ... Read More

How can I round a number to 1 decimal place in JavaScript?

Shubham Vora
Updated on 26-Dec-2024 15:22:17

32K+ Views

In this tutorial, we will learn to round a number to a one decimal place in JavaScript. There are various needs to round the float numbers and show particular digits after the decimal point. In our case, we need to show only the digit after the decimal point. However, we will create a customizable manual function that can round off the number and show the particular number of digits after the decimal point at the end of this tutorial. This example lets users understand the fundamental need to round a number to a single decimal digit. Suppose the scenario where ... Read More

Advertisements