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
Web Development Articles
Page 430 of 801
What are associative Arrays in JavaScript?
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 MoreExplain common code blocks in JavaScript switch statement?
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 MoreExplain Strict Comparison in JavaScript switch statement?
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 MoreExplain JavaScript Regular Expression modifiers with examples
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 MoreHow to test and execute a regular expression in JavaScript?
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 MoreCheck for Ugly number in JavaScript
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 MoreHow to preview an image before it is uploaded in JavaScript?
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 MoreLeaders array JavaScript
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 MoreHide div that contains specific text with JavaScript?
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 MoreMersenne prime in JavaScript
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