Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Javascript Articles
Page 273 of 534
How to write JavaScript Regular Expression for multiple matches?
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 MoreWhat is function overloading in JavaScript?
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 MoreHow much should be a JavaScript Line Length?
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 MoreHow to create a table caption with JavaScript DOM?
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 MoreWhich is the JavaScript RegExp to find any alternative text?
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 MoreHow to perform Multiline matching with JavaScript RegExp?
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 MoreWhat is the usage of in operator in JavaScript?
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 MoreWith JavaScript RegExp find a character except newline?
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 MoreWith JavaScript Regular Expression find a non-whitespace character.
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 MoreWith JavaScript RegExp search a carriage return character.
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