Found 6710 Articles for Javascript

How can I convert a string to boolean in JavaScript?

Shubham Vora
Updated on 12-Jul-2022 13:50:50

1K+ Views

This tutorial teaches us to convert the string to the boolean in JavaScript. Suppose that while developing the application, we have stored the boolean value in the database or local storage in the string format. Now, based on the stored string value, we want to convert it to a boolean value and perform a particular operation for the application user; the question arises how can we convert a string to a boolean?There can be many possible ways to solve the above problem. We will learn some useful methods in this tutorial.Using the Comparison (==) and Ternary operator (? :)Using the Boolean classUsing ... Read More

What is a constructor to create String object in JavaScript?

Akshaya Akki
Updated on 15-Jun-2020 07:09:25

158 Views

To create a String object in JavaScript, use string.constructor. A constructor returns a reference to the string function that created the instance's prototype.ExampleYou can try to run the following code to create a String object with the constructor −Live Demo           JavaScript String constructor Method                        var str = new String( "This is string" );          document.write("str.constructor is:" + str.constructor);          

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

Manikanth Mani
Updated on 15-Jun-2020 06:59:06

1K+ Views

To get the first index of an occurrence of the specified value in a string, use the JavaScript indexOf() method.ExampleYou can try to run the following code to get the first index −Live Demo           JavaScript String indexOf() Method                        var str = new String( "Learning is fun! Learning is sharing!" );          var index = str.indexOf( "Learning" );          document.write("First index of string Learning :" + index );          

How to convert a boolean value to string value in JavaScript?

Alankritha Ammu
Updated on 15-Jun-2020 06:58:38

16K+ Views

To convert a Boolean value to string value in JavaScript, use the toString() method. This method returns a string of either "true" or "false" depending upon the value of the object.ExampleYou can try to run the following code to convert a boolean value to string value −Live Demo           JavaScript toString() Method                        var flag = new Boolean(true);          document.write( "flag.toString is : " + flag.toString() );          

How to turn JavaScript array into the comma-separated list?

Abhishek
Updated on 25-Nov-2022 07:54:13

12K+ Views

In this tutorial, we will learn how we can change the elements of a JavaScript array in a comma-separated list. Sometimes, we need the elements of a JavaScript array in a format that is not returned by the array itself by default, so we need to write some extra code to implement this task. Fortunately, JavaScript allows us to do so by using some in-built methods. We will discuss these methods in detail. Following are the in-built methods provided by JavaScript to convert the array into a comma-separated list − Array join() method Array toString method Let us ... Read More

How to create a blink text using JavaScript?

Anjana
Updated on 15-Jun-2020 06:56:11

5K+ Views

To create a blinking text, use the JavaScript blink() method. This method causes a string to blink as if it were in a BLINK tag.Note − HTML tag deprecated and is not expected to work in every browser.ExampleYou can try to run the following code to create a blinking text with the JavaScript blink() method −Live Demo           JavaScript String blink() Method                        var str = new String("Demo Text");          document.write(str.blink());          document.write(" Note: HTML tag deprecated and is not expected to work in every browser.")          

How to create a big font text using JavaScript?

Akshaya Akki
Updated on 15-Jun-2020 06:55:29

944 Views

To create a big font text, use the JavaScript big() method. This method causes a string to be displayed in a big font as if it were in a BIG tag.ExampleYou can try to run the following code to create a big font text −Live Demo           JavaScript String big() Method                        var str = new String("Demo Text");          document.write("Following is bigger text: "+str.big());          

How to create a link from a text using JavaScript?

Manikanth Mani
Updated on 15-Jun-2020 06:54:37

2K+ Views

To create a link, use the JavaScript link() method. This method creates an HTML hypertext link that requests another URL. The following is the syntax:string.link( hrefname )Above, hrefname is any string that specifies the HREF of the tag; it should be a valid URL.ExampleYou can try to run the following code to learn how to work with link() method in JavaScript −Live Demo           JavaScript String link() Method                        var str = new String("Simply Easy Learning");          var URL = "http://www.tutorialspoint.com";          document.write(str.link( URL ));          

How to change string to be displayed as a subscript using JavaScript?

Shubham Vora
Updated on 02-Aug-2022 11:32:20

3K+ Views

In this tutorial, we will learn to change the string displayed as a subscript using JavaScript. The meaning of the subscript string is a string that displays right after the string with a small letter and hangs below. For example, In the Astart, ‘start’ is the subscript string shown in the small letter right after A and hangs below. The substring uses in many fields such as Mathematics, chemicals, etc. It is useful to represent the chemical name. For example, H2, N2, O2, etc. Also, we can use it in mathematics to show the symbols such as X2, A2, etc. ... Read More

How to create a small font text using JavaScript?

Anjana
Updated on 15-Jun-2020 06:52:29

685 Views

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

Advertisements