Found 6710 Articles for Javascript

How to create a strikethrough text using JavaScript?

Akshaya Akki
Updated on 15-Jun-2020 06:52:04

5K+ Views

To create a strikethrough text with JavaScript, use the strike() method. This method causes a string to be displayed as struck-out text as if it were in a tag.ExampleYou can try to run the following code to create a strikethrough text −Live Demo           JavaScript String strike() Method                        var str = new String("Demo Text");          document.write(str.strike());          alert(str.strike());          

How to make a text italic using JavaScript

Shubham Vora
Updated on 20-Oct-2022 07:20:05

4K+ Views

In this tutorial, we will learn to make a text italic using JavaScript. We give the italic property to a text to differentiate it from other text within the sentence. In HTML, we can make a text italic by just adding the text within the 'i' tag. But sometimes, we have to make it dynamic, that not possible with HTML. Then, we have to use a programming language like JavaScript to make the text italic. Let's have a look at how to make a text italic using JavaScript. Following are the ways by which we can make a ... Read More

How to change the font size of a text using JavaScript?

Shubham Vora
Updated on 08-Aug-2022 08:32:48

7K+ Views

In this tutorial, programmers will learn to change the font size of the text using JavaScript. Many application allows users to change the font size according to users’ requirement. We need to change the default font size using JavaScript to achieve that. Before we move ahead with the tutorial, let’s learn what values we can assign to the fontsize. Different values users can assign to the font size We can assign the below values to the font size of any element. Every values changes the font size differently which we have explained here. xx-large | x-large | large | ... Read More

How to change the font color of a text using JavaScript?

Shubham Vora
Updated on 12-Sep-2023 01:06:22

43K+ Views

This tutorial teaches us to change the font color of the text using JavaScript. While working with JavaScript and developing the frontend of the application, it needs to change the font color of the text using JavaScript when an event occurs. For example, we have an application which can turn on or off the device. We have a button to turn on or off the device. When the device is on, make the button text green. Otherwise, make the button text red. So, in such cases, programmers need to change the font color using JavaScript. We have some different method ... Read More

How to create a bold text using JavaScript?

Anjana
Updated on 15-Jun-2020 06:48:12

18K+ Views

To create a bold text using JavaScript, use the bold() text. This method causes a string to be displayed as bold as if it were in a tag.ExampleYou can try to run the following code to create a bold text with JavaScript −Live Demo           JavaScript String bold() Method                        var str = new String("Demo Text");          document.write(str.bold());          alert(str.bold());          

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

576 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

Advertisements