Articles on Trending Technologies

Technical articles with clear explanations and examples

Extract a number from a string using JavaScript

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 38K+ Views

In JavaScript, there are multiple ways to extract a number from a string. One way is to use the match() method and a regular expression to search for all numeric digits in the string. Another way is to use the replace() method and a regular expression to remove all nonnumeric characters from the string, leaving only the numbers. Let's understand each of the methods with the help of some examples. Using the match() method and regular expression The regular expression is one kind of search pattern which we can create by combining multiple alphabetic and special characters. ...

Read More

How to Become a JavaScript Developer?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 558 Views

A JavaScript developer is a programmer who specializes in creating interactive and dynamic web applications using JavaScript, the world's most popular programming language. JavaScript developers build everything from simple website interactions to complex single-page applications, mobile apps, and even server-side applications using Node.js. JavaScript developers work on both front-end development (user-facing interfaces) and back-end development (server-side logic). They collaborate with designers, other developers, and stakeholders to create responsive, user-friendly web experiences that run seamlessly across different browsers and devices. Essential Skills for JavaScript Developers To become a successful JavaScript developer, you'll need to master several core technologies ...

Read More

How to merge two strings alternatively in JavaScript

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

In JavaScript, merging two strings alternatively means combining characters from both strings one by one. This creates a new string where characters alternate between the first and second input strings. For example, if we have two strings: const str1 = 'abc'; const str2 = 'def'; console.log('String 1:', str1); console.log('String 2:', str2); String 1: abc String 2: def The expected output should be: adbecf Using Loop-Based Approach Here's a function that merges two strings alternatively by iterating through both strings simultaneously: const str1 = 'abc'; const ...

Read More

Get price value from span tag and append it inside a div after multiplying with a number in JavaScript?

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

In JavaScript, you can extract a numeric value from a span element, multiply it, and display the result in another element. This involves getting the text content, converting it to a number, performing the calculation, and updating the DOM. HTML Structure First, let's create a proper HTML structure with a span containing the price and a div to display the result: Price Calculator Original ...

Read More

JavaScript checking if all the elements are same in an array

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 698 Views

In this article, we will learn to check if all the elements are the same in an array in JavaScript. Finding all elements of an array to be the same is a frequent problem in JavaScript, usually needed for data validation, game logic, and algorithm building. Problem Statement We are required to write a JavaScript function that takes in an array of literals. The function should find whether or not all the values in the array are the same. If they are the same, the function should return true, or false otherwise. For Example Input ...

Read More

Return the element that appears for second most number of times in the array JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 589 Views

In JavaScript, finding the element that appears for the second most number of times in an array requires counting frequencies and identifying the second highest count. We'll use a frequency map and sorting to solve this problem efficiently. Understanding the Problem Given an array of elements, we need to find the element with the second highest frequency. For example, in the array [1, 3, 3, 4, 4, 4], the element 4 appears 3 times (most frequent), and 3 appears 2 times (second most frequent), so we return 3. Algorithm Steps Step 1: Create a frequency map ...

Read More

Find the greatest product of three numbers in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 741 Views

In JavaScript, finding the greatest product of three numbers from an array requires considering both positive and negative numbers. This problem has multiple approaches, from brute force to optimized sorting methods. Understanding the Problem Given an array of integers, we need to find three numbers whose product is the largest among all possible combinations. For example, with array [1, 5, 3, 2, 4], the three largest numbers (3, 4, 5) give us the product 3 × 4 × 5 = 60. ...

Read More

Largest product of n contiguous digits of a number in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 283 Views

We are required to write a JavaScript function that takes in two numbers as first and the second argument, let us call them m and n. The first number will generally be a number with multiple digits and the second number will always be smaller than the number of digits in the first number. The function should find the group of n consecutive digits from m whose product is the greatest. For example, if the input numbers are: const m = 65467586; const n = 3; Then the output should be: ...

Read More

Nth smallest element in sorted 2-D array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 515 Views

In JavaScript, finding the Nth smallest element in a sorted 2D array requires an efficient approach. We'll use binary search on the value range rather than indices. Problem Statement Given a sorted 2D array (sorted in increasing order both row-wise and column-wise), find the Nth smallest element. const arr = [ [ 1, 5, 9], [10, 11, 13], [12, 13, 15] ]; For example, if we want the 5th smallest element from the above array, the answer would be 11. Approach: Binary Search on Values ...

Read More

Sum all perfect cube values upto n using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 387 Views

Problem We are required to write a JavaScript function that takes in a number n and returns the sum of all perfect cube numbers smaller than or equal to n. Understanding Perfect Cubes Perfect cubes are numbers that can be expressed as n³ where n is an integer. For example: 1³ = 1, 2³ = 8, 3³ = 27, 4³ = 64, etc. Example Following is the code − const num = 23546; const sumPerfectCubes = (num = 1) => { let i = 1; let sum = 0; while(i * i * i

Read More
Showing 15131–15140 of 61,299 articles
Advertisements