Javascript Articles - Page 588 of 671

Match any string with p at the end of it.

Anjana
Updated on 23-Jun-2020 08:40:30

152 Views

To match any string with p at the end of it with JavaScript RegExp, use the p$ Quantifier.Example           JavaScript Regular Expression                        var myStr = "Welcome to our website! Welcome";          var reg = /me$/g;          var match = myStr.match(reg);                    document.write(match);          

How to convert Number to Boolean in JavaScript?

Shubham Vora
Updated on 10-Aug-2022 12:18:29

2K+ Views

This tutorial will teach us to convert a number to a Boolean in JavaScript. The variable of Boolean data type can contain only two values, true and false. When we convert the variables of any other data type to Boolean, it returns true for all non-falsy values and false for all falsy values. Let’s understand the falsy values. The JavaScript contains 6+ falsy values, and some of them are as below. Null 0 NaN False Undefined ‘ ’ From the above falsy values, we can say that for 0, we will get the false Boolean value and for ... Read More

How to convert Boolean to Number in JavaScript?

Shubham Vora
Updated on 08-Aug-2022 09:18:13

4K+ Views

In this tutorial, we will convert Boolean to Number in JavaScript. The Boolean is the variable's data type, which is supported by JavaScript like the other programming languages. The Boolean data type contains only two values, true and false. In some cases, programmers must convert the true or false value to the number. For example, using the strict equality operator to compare the Boolean value with the number variable. Here, using different operators, we have three methods to convert the Boolean to a number. Using the Number() Function In JavaScript, the Number() function is useful to convert any variable to ... Read More

How to show name/value pairs of cookies in a document with JavaScript?

Abhishek Kumar
Updated on 21-Sep-2022 07:34:32

859 Views

We use the cookie property of the document object to show the name/value pairs of cookies 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. A server serves requests when a connection is set up and forgets everything about the user as soon as the connection is closed. This posed a nasty problem of bad user experience to the community. A cookie, resolves this problem by storing small but ... Read More

Match any string containing a sequence of two to three p's.

Akshaya Akki
Updated on 20-Jan-2020 10:11:41

118 Views

To match any string containing a sequence of two to three p’s with JavaScript RegExp, use the p{2,3} Quantifier.Example           JavaScript Regular Expression                        var myStr = "Welcome 1, 10, 100, 1000, 1000";          var reg = /\d{2,3}/g;          var match = myStr.match(reg);                    document.write(match);          

How to add properties and methods to an object in JavaScript?

V Jyothi
Updated on 23-Jun-2020 08:32:13

265 Views

To add properties and methods to an object in JavaScript, use the prototype property.ExampleYou can try to run the following code to learn how to work with prototype −           JavaScript prototype property                function book(title, author) {             this.title = title;             this.author = author;          }                              var myBook = new book("Amit", "Java");          book.prototype.price = null;          myBook.price = 500;          document.write("Book title is : " + myBook.title + "");          document.write("Book author is : " + myBook.author + "");          document.write("Book price is : " + myBook.price + "");          

How to show the domain name of the server that loaded the document with JavaScript?

Abhishek Kumar
Updated on 21-Sep-2022 07:40:55

3K+ Views

We use the window.location.hostname property of the document object to show the domain name of the server that loaded the document using 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. Every resource or computer that is available on the internet has an address that is either IPV4 (192.88.99.255) or IPV6 (2001:db8:3333:4444:5555:6666:7777:8888). These addresses are good for computers but not for us. domain name system is a layer of abstraction over that organization ... Read More

Match any string containing a sequence of N p's

Sai Nath
Updated on 23-Jun-2020 08:33:12

171 Views

To match any string containing a sequence of N p’s with JavaScript RegExp, use the p{N} Quantifier.ExampleYou can try to run the following code to match any string containing a sequence of N p’s −           JavaScript Regular Expression                        var myStr = "Welcome 1, 100, 10000, 1000";          var reg = /\d{3}/g;          var match = myStr.match(reg);                    document.write(match);          

Match any string containing zero or more p's.

Abhinaya
Updated on 23-Jun-2020 08:33:40

195 Views

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

How to find the number of anchors with JavaScript?

Abhishek
Updated on 31-Oct-2022 08:03:31

277 Views

In this tutorial, we will learn how to find the number of anchors used in an HTML document with JavaScript. Sometimes, During the development of a web page, the developer may need to add multiple links to the different buttons present on the webpage using multiple anchors for each button. In such a situation, if you want to find the number of anchor elements, you can use the anchors property. JavaScript allows us to use the anchors property to count the number of anchors ( elements) in an HTML document. Note − The document.anchors property is deprecated and no longer ... Read More

Advertisements