Javascript Articles

Page 273 of 534

How to write JavaScript Regular Expression for multiple matches?

Nikitha N
Nikitha N
Updated on 15-Mar-2026 260 Views

To find multiple matches in JavaScript, use the global flag (g) with regular expressions. The exec() method can be called repeatedly to find all matches in a string. Syntax let regex = /pattern/g; let matches; while ((matches = regex.exec(string)) !== null) { // Process each match } Example: Extracting URL Parameters This example extracts all demo parameters from a URL query string: var url = 'https://www.example.com/new.html?ui=7&demo=one&demo=two&demo=three'; var a = document.createElement('a'); a.href = url; var demoRegex = /(?:^|[&;])demo=([^&;]+)/g; var matches; var demo = []; ...

Read More

What is function overloading in JavaScript?

Ankitha Reddy
Ankitha Reddy
Updated on 15-Mar-2026 2K+ Views

JavaScript does not support function overloading like other programming languages such as Java or C++. When you define multiple functions with the same name, JavaScript keeps only the last defined function. What Happens with Same Function Names Let's see what happens when we define multiple functions with the same name: function funcONE(x, y) { return x * y; } function funcONE(z) { return z; } // Only the last function definition is kept console.log(funcONE(5)); // prints 5 console.log(funcONE(5, 6)); // prints ...

Read More

How much should be a JavaScript Line Length?

Nitya Raut
Nitya Raut
Updated on 15-Mar-2026 822 Views

JavaScript line length refers to how many characters should fit on a single line of code. Following proper line length guidelines makes your code more readable and maintainable. Recommended Line Length The standard practice is to keep JavaScript lines under 80 characters. Some modern style guides allow up to 100 or 120 characters, but 80 remains the most widely adopted standard for better readability across different editors and devices. Breaking Long Lines When a statement exceeds the character limit, break it after a comma or operator, not in the middle of a variable name or string. ...

Read More

How to create a table caption with JavaScript DOM?

Jai Janardhan
Jai Janardhan
Updated on 15-Mar-2026 653 Views

To create a table caption using JavaScript DOM, use the createCaption() method on a table element. This method adds a element to the table, which displays as a title above the table content. Syntax table.createCaption() Return Value Returns the newly created element, which can be styled or modified with text content. Example Here's how to create a table caption dynamically using JavaScript: function captionFunc(x) { ...

Read More

Which is the JavaScript RegExp to find any alternative text?

Nikitha N
Nikitha N
Updated on 15-Mar-2026 269 Views

To match any of the specified alternatives in JavaScript, use the alternation operator | within parentheses. This pattern allows you to find multiple possible text options in a single regular expression. Syntax (option1|option2|option3) The pipe symbol | acts as an OR operator, matching any one of the alternatives listed within the parentheses. Example Here's how to find alternative text patterns using JavaScript RegExp: JavaScript Regular Expression var myStr = "one, ...

Read More

How to perform Multiline matching with JavaScript RegExp?

Moumita
Moumita
Updated on 15-Mar-2026 687 Views

To perform multiline matching in JavaScript, use the m flag with regular expressions. This flag makes ^ and $ anchors match the beginning and end of each line, not just the entire string. Syntax /pattern/m new RegExp("pattern", "m") How the m Flag Works Without the m flag, ^ matches only the start of the string and $ matches only the end. With the m flag, they match line boundaries created by (newline) characters. Example: Basic Multiline Matching JavaScript Regular ...

Read More

What is the usage of in operator in JavaScript?

Arushi
Arushi
Updated on 15-Mar-2026 186 Views

The in operator is used in JavaScript to check whether a property exists in an object or not. It returns true if the property is found, and false otherwise. Syntax propertyName in object Basic Example Here's how to use the in operator to check for properties in objects: var emp = {name: "Amit", subject: "Java"}; document.write("name" in emp); document.write(""); document.write("subject" in emp); document.write(""); document.write("age" in emp); document.write(""); document.write("MAX_VALUE" in Number); true true false true Checking Array Indices The in ...

Read More

With JavaScript RegExp find a character except newline?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 283 Views

To find a character except for a newline, use the dot metacharacter . (period). The dot matches any single character except the newline character (). Syntax /./ // Matches any character except newline /.+/ // Matches one or more characters except newline /a.b/ // Matches 'a', any character, then 'b' Example JavaScript Regular Expression ...

Read More

With JavaScript Regular Expression find a non-whitespace character.

Daniol Thomas
Daniol Thomas
Updated on 15-Mar-2026 498 Views

To find a non-whitespace character in JavaScript regular expressions, use the \S metacharacter. This matches any character that is not a space, tab, newline, or other whitespace character. Syntax \S // Matches any non-whitespace character \S+ // Matches one or more non-whitespace characters \S* // Matches zero or more non-whitespace characters Example: Finding Non-Whitespace Characters JavaScript Regular Expression ...

Read More

With JavaScript RegExp search a carriage return character.

Ayyan
Ayyan
Updated on 15-Mar-2026 736 Views

To find carriage return characters with JavaScript Regular Expression, use the \r metacharacter. This pattern matches the carriage return character (ASCII code 13) in strings. Syntax /\r/ Example: Finding Carriage Return Position The following example shows how to search for a carriage return character and return its position in the string: JavaScript Regular Expression ...

Read More
Showing 2721–2730 of 5,340 articles
« Prev 1 271 272 273 274 275 534 Next »
Advertisements