Web Development Articles

Page 430 of 801

What are associative Arrays in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 4K+ Views

Associative arrays are basically objects in JavaScript where indexes are replaced by user-defined keys. They do not have a length property like normal arrays and cannot be traversed using a normal for loop. What are Associative Arrays? In JavaScript, what we call "associative arrays" are actually objects. Unlike traditional arrays that use numeric indexes, associative arrays use string keys to access values. This makes them perfect for storing key-value pairs where you need meaningful identifiers. Creating Associative Arrays You can create associative arrays using object literal syntax or by assigning properties to an empty object: ...

Read More

Explain common code blocks in JavaScript switch statement?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 320 Views

Common code blocks in JavaScript switch statements allow multiple cases to share the same execution code. This is achieved by omitting the break statement, causing execution to "fall through" to subsequent cases. What are Common Code Blocks? Common code blocks occur when multiple case values need to execute the same code. Instead of duplicating code, you can group cases together by omitting break statements. Syntax switch (expression) { case value1: case value2: case value3: // ...

Read More

Explain Strict Comparison in JavaScript switch statement?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 474 Views

The JavaScript switch statement performs strict comparison (===) to match values. This means both value and type must be identical for a case to execute. If no strict match is found, the default case runs. Understanding Strict Comparison Strict comparison checks both value and type. For example, the number 1 is not equal to the string "1" in strict comparison: Strict Comparison Demo // Demonstrating strict vs loose comparison ...

Read More

Explain JavaScript Regular Expression modifiers with examples

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 713 Views

JavaScript regular expression modifiers are optional flags that modify how the pattern matching behaves. These modifiers enable features like case-insensitive matching, global searching, and multiline matching. Available Modifiers Modifier Name Description ...

Read More

How to test and execute a regular expression in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 333 Views

JavaScript provides two main methods for testing and executing regular expressions: test() and exec(). The test() method returns a boolean indicating if a pattern matches, while exec() returns detailed match information or null. Regular Expression Methods There are two primary ways to work with regular expressions in JavaScript: test() - Returns true/false if pattern matches exec() - Returns match details or null Example: Using test() and exec() Regular Expression Testing ...

Read More

Check for Ugly number in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

In the decimal number system, ugly numbers are positive integers whose only prime factors are 2, 3, or 5. This means an ugly number can be expressed as 2i × 3j × 5k where i, j, and k are non-negative integers. For example, the integers 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 are all ugly numbers because they only contain the prime factors 2, 3, and 5. However, 7, 11, 13, 14 are not ugly numbers as they contain other prime factors. Algorithm To check if a number is ugly, we repeatedly divide it ...

Read More

How to preview an image before it is uploaded in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 371 Views

In JavaScript, you can preview an image before uploading using the FileReader API. This allows users to see their selected image immediately without needing to upload it to a server first. How FileReader Works The FileReader API reads file contents asynchronously. For image preview, we use readAsDataURL() which converts the image file into a base64 data URL that can be displayed in an element. Example Image Preview Example ...

Read More

Leaders array JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 423 Views

An element in an array is a leader if it is greater than all elements on its right side. The rightmost element is always a leader since there are no elements to its right. For example, in the array [23, 55, 2, 56, 3, 6, 7, 1]: 56 is a leader (greater than 3, 6, 7, 1) 7 is a leader (greater than 1) 1 is a leader (rightmost element) Input: [23, 55, 2, 56, 3, 6, 7, 1] Output: [56, 7, 1] Using reduceRight() Method The most efficient approach is ...

Read More

Hide div that contains specific text with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

In JavaScript, you can hide div elements containing specific text by using getElementsByClassName() to select elements, then iterating through them and checking their content. When a match is found, set the element's display style to 'none'. Basic Approach The process involves three main steps: Get all div elements with a specific class Loop through each element and check its text content Hide matching elements by setting display: none Example: Hide Divs with Specific Text Hide ...

Read More

Mersenne prime in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 356 Views

In Mathematics, a Mersenne prime is a number that can be written in the form M(n) = 2^n − 1 for some integer n and is actually a prime number. For example − The first four Mersenne primes are 3, 7, 31, and 127, which correspond to n = 2, 3, 5, and 7 respectively: 2² − 1 = 3 2³ − 1 = 7 2⁵ − 1 = 31 2⁷ − 1 = 127 We need to write a JavaScript function that ...

Read More
Showing 4291–4300 of 8,010 articles
« Prev 1 428 429 430 431 432 801 Next »
Advertisements