AmitDiwan

AmitDiwan

8,392 Articles Published

Articles by AmitDiwan

Page 439 of 840

Converting string to MORSE code in JavaScript

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

What is Morse Code? Morse code is a method used in telecommunications to encode text characters as standardized sequences of two different signal durations, called dots and dashes. Each letter of the alphabet has a unique pattern of dots (.) and dashes (-). To convert a string to Morse code in JavaScript, we need an object that maps all alphabets to their Morse code equivalents, then iterate through the input string to build the encoded result. Morse Code Map First, let's create an object containing all alphabet-to-Morse mappings: const morseCode = { ...

Read More

How to match strings that aren't entirely digits in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 115 Views

In JavaScript, you can use regular expressions to match strings that contain non-digit characters. This is useful when parsing complex data strings where you need to identify values that aren't purely numeric. Problem Statement Consider this complex string containing various data types: studentId:"100001",studentName:"John Smith",isTopper:true,uniqueId:10001J-10001,marks:78,newId:"4678" We want to extract values that contain characters other than digits, excluding boolean values and null. Using Regular Expression The following regular expression matches strings that aren't entirely digits: var regularExpression = /(?

Read More

How to remove elements using the splice() method in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 366 Views

The splice() method is used to remove elements from an array by specifying the starting index and the number of elements to delete. It modifies the original array and returns an array of the removed elements. Syntax array.splice(startIndex, deleteCount) Parameters startIndex: The index at which to start removing elements deleteCount: The number of elements to remove Example: Remove Single Element Splice Method Example Remove Elements using ...

Read More

Keyed collections in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 722 Views

Keyed collections are data structures in JavaScript where elements are organized by keys rather than indices. The two main keyed collections are Map and Set objects, which maintain insertion order and provide efficient key-based operations. Map Collection A Map object holds key-value pairs and remembers the original insertion order of the keys. Unlike objects, Map keys can be of any type. Map Collection Example Map Collection Demo ...

Read More

How to get the product of two integers without using * JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 385 Views

We are required to write a function that takes in two numbers and returns their product, but without using the (*) operator. Method 1: Using Division Operator We know that multiplication and division are inverse operations, so if we divide a number by another number's inverse, it's the same as multiplying the two numbers. The mathematical concept: a × b = a ÷ (1 ÷ b) const a = 20, b = 45; const product = (a, b) => a / (1 / b); console.log(product(a, b)); 900 Method 2: Using ...

Read More

How to compare two arrays in JavaScript and make a new one of true and false? JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 527 Views

We have 2 arrays in JavaScript and we want to compare one with the other to see if the elements of master array exists in keys array, and then make one new array of the same length that of the master array but containing only true and false (being true for the values that exists in keys array and false the ones that don't). Let's say, if the two arrays are − const master = [3, 9, 11, 2, 20]; const keys = [1, 2, 3]; Then the final array should be − ...

Read More

Display all the values of an array in p tag on a web page with JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 828 Views

In JavaScript, you can display array values as paragraph elements on a web page using several approaches. Here are the most common methods without requiring external libraries. Method 1: Using forEach() with createElement Display Array Values const arrayValues = [1000000001, "John", "Smith", 100, 200, 3000]; const container ...

Read More

JavaScript symbol.@@toPrimitive() function

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 182 Views

The Symbol.toPrimitive method defines how an object should be converted to a primitive value when used in operations that require type coercion. This method is called automatically by JavaScript when an object needs to be converted to a primitive type. Syntax object[Symbol.toPrimitive](hint) The hint parameter specifies the preferred type of conversion: "number" - when numeric conversion is preferred "string" - when string conversion is preferred "default" - when no specific preference (used in == comparison) Basic Example Symbol.toPrimitive ...

Read More

How to declare Block-Scoped Variables in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 279 Views

Block-scoped variables are declared using let and const keywords introduced in ES2015. Unlike var, these variables are only accessible within their containing block. Block scope means the variable exists only within the nearest enclosing curly braces {}. Syntax let variableName = value; const constantName = value; Example: Basic Block Scope Block Scoped Variables Block Scoped Variables Demo Test Block Scope ...

Read More

Loading JavaScript modules dynamically

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 256 Views

Dynamic module loading allows you to import JavaScript modules at runtime rather than at compile time. This enables lazy loading, conditional imports, and better performance optimization. Static vs Dynamic Import Static imports happen at the top of files and load immediately. Dynamic imports use the import() function to load modules on demand. Dynamic Module Loading body { ...

Read More
Showing 4381–4390 of 8,392 articles
« Prev 1 437 438 439 440 441 840 Next »
Advertisements