Javascript Articles - Page 589 of 671

How to show the number of links in a document with JavaScript?

Abhishek Kumar
Updated on 21-Sep-2022 07:58:03

782 Views

We use the links property of the document object to show the number of links in a document with JavaScript. The document object, part of the DOM, corresponds to the current web page that the browser has loaded. It Contains all the information about the condition of the browser as well as the web page. The links is a property of the document object that returns a list of all the hyperlinks present in the HTML document. A hyperlink may look something like this − "https://www.tutorialpoints.com/php" The links property of the document object lists all HTML elements having href ... Read More

Match any string containing at most one p.

Ayyan
Updated on 23-Jun-2020 08:26:03

183 Views

To match any string containing zero or one p’s with JavaScript RegExp, use the p? Quantifier.ExampleYou can try to run the following code to match any string containing zero or one p. Here p is considered a number of occurrences −           JavaScript Regular Expression                        var myStr = "Welcome 1, 100, 10000, 10000";          var reg = /10?/g;          var match = myStr.match(reg);                    document.write(match);          

How is NaN converted to Number in JavaScript?

Saurabh Jaiswal
Updated on 11-Aug-2022 14:35:24

10K+ Views

In this article, we will learn how to convert NaN to a Number. NaN in Javascript means Not a Number, whose type is Number but actually, it is not a number. To Convert, the NaN to a Number we use Multiple methods some of which are discussed below. Using the OR (||) operator Using the isNaN() method Using the ~~ operator Using Ternary Operator Using the OR (||) Operator The OR operator is represented by the || sign in JavaScript. To convert the NaN into a number we use the OR operator with NaN and any number and ... Read More

How to apply a function simultaneously against two values of the array from right-to-left?

Nitya Raut
Updated on 23-Jun-2020 08:31:18

100 Views

Use the reduceRight() method in JavaScript to apply a function simultaneously against two values of the array from right-to-left as to reduce it to a single value.The following are the parameters −callback − Function to execute on each value in the array.initialValue − Object to use as the first argument to the first call of the callbackExampleYou can try to run the following code to learn how to work with reduceRight() method in JavaScript −           JavaScript Array reduceRight Method                        if (!Array.prototype.reduceRight)         ... Read More

Match any string containing one or more p's with JavaScript RegExp.

Moumita
Updated on 23-Jun-2020 08:26:48

205 Views

To match any string containing one or more p’s with JavaScript RegExp, use the p+ Quantifier.ExampleYou can try to run the following code to match any string containing one or more p’s. Here p is considered as a number of occurrences −           JavaScript Regular Expression                        var myStr = "Secure and Responsive!";          var reg = /s+/g;          var match = myStr.match(reg);                    document.write(match);          

What is the role of filter() method in JavaScript?

Ankitha Reddy
Updated on 30-Jul-2019 22:30:21

277 Views

JavaScript array filter() method creates a new array with all elements that pass the test implemented by the provided function. The following are the parameters − callback − Function to test each element of the array. thisObject − Object to use as this when executing callback. You can try to run the following code to learn how to work with filter() method in JavaScript − Example Live Demo JavaScript Array filter Method ... Read More

How to convert Boolean to String in JavaScript?

Shubham Vora
Updated on 10-Aug-2022 11:46:24

3K+ Views

In this tutorial, we will learn to convert the Boolean to string in JavaScript. The problem is straightforward: sometimes programmers need to use the boolean true and false values as a string. So, there is a requirement to convert the Boolean to string. Here, we have various methods to convert the Boolean to a string variable. Using the toString() Method Using + and $ (template literal) Operator Using the ternary Operator Using the toString() method The toString() method is the JavaScript string library method, which is useful for converting the variables to the string data type. We can ... Read More

How to find the name of the first form in a document with JavaScript?

Abhishek
Updated on 31-Oct-2022 08:01:48

1K+ Views

In this tutorial, we will learn how to find the name of the first form in an HTML document. Sometimes, we use more than one form tags in the HTML document for different purposes. At that time, we can face difficulties in finding the specific element to add some more properties to it. In such conditions, we can use the forms property of the "document" interface to access all the elements present in the document individually as well as collectively Document.forms As we discussed above, the forms property is used to access all the forms present in the ... Read More

How to represent the source code of an object with JavaScript Arrays?

Govinda Sai
Updated on 23-Jun-2020 08:28:59

277 Views

JavaScript array toSource() method returns a string representing the source code of the array. This method is supported by Mozilla.ExampleYou can try to run the following code to learn how to represent the source code of an object with JavaScript Arrays −           JavaScript Array toSource Method                        var arr = new Array("football", "baseball", "volleyball", "cricket");                  var str = arr.toSource();          document.write("Returned string is : " + str );          

How to get the number of forms in a document with JavaScript?

Shubham Vora
Updated on 14-Sep-2022 08:47:27

1K+ Views

In this tutorial, we will learn how to get the number of forms in a document using JavaScript. Since different methods are used to create forms in an HTML document, it might get tricky to get the number of forms present. However, you can use some methods to count the forms created without the form tag. Using the length Property The most widely accepted method to create forms in HTML documents is using the tag. Some websites also use tags to create forms in the document. Hence, we will discuss the method to get the number of forms ... Read More

Advertisements