Articles on Trending Technologies

Technical articles with clear explanations and examples

Explain the working of timers in JavaScript

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 748 Views

In JavaScript, timers are a very noteworthy feature. As like the normal watch timer, we can start the timer at a time and execute the function or code in JavaScript after a particular time. In simple terms, we can use the timer to execute the code after some delay. For example, when you visit some website, it shows the signup box after 3 to 4 minutes of your visit, and that we can achieve using JavaScript. We can set the delay timer to show the signup popup box. Another good example of the timer in real life is ...

Read More

Retaining array elements greater than cumulative sum using reduce() in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 214 Views

We need to write a JavaScript function that takes an array of numbers and returns a new array containing only elements that are greater than the cumulative sum of all previous elements. We'll solve this using the Array.prototype.reduce() method. Problem Understanding For each element in the array, we compare it with the sum of all elements that came before it. If the current element is greater than this cumulative sum, we include it in the result array. Example Let's implement the solution using reduce(): const arr = [1, 2, 30, 4, 5, 6]; ...

Read More

How can I merge properties of two JavaScript objects dynamically?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 310 Views

To merge properties of two JavaScript objects dynamically, you can use the spread operator ({...object1, ...object2}) or Object.assign(). Both methods create a new object containing properties from multiple source objects. Using Spread Operator (Recommended) The spread operator is the modern and most concise approach: var firstObject = { firstName: 'John', lastName: 'Smith' }; var secondObject = { countryName: 'US' }; var mergedObject = {...firstObject, ...secondObject}; console.log(mergedObject); { firstName: 'John', lastName: 'Smith', countryName: 'US' } Using Object.assign() ...

Read More

Subtracting array in JavaScript Delete all those elements from the first array that are also included in the second array

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 211 Views

Subtracting arrays in JavaScript involves removing all elements from the first array that exist in the second array. This operation is useful for filtering data and finding differences between datasets. Problem Statement Given two arrays, we need to delete all elements from the first array that are also present in the second array. const arr1 = ['uno', 'dos', 'tres', 'cuatro']; const arr2 = ['dos', 'cuatro']; // Expected output: ['uno', 'tres'] Using filter() with indexOf() The filter() method creates a new array with elements that pass a test. We use indexOf() to check ...

Read More

Fetch Numbers with Even Number of Digits JavaScript

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

In JavaScript, finding numbers with an even count of digits means identifying numbers where the total digit count is divisible by 2. This is different from finding even numbers themselves. Understanding the Problem We need to create a function that takes an array of numbers and returns only those numbers that have an even number of digits. For example, in the array [12, 345, 67, 8910, 11, 9], the numbers 12 (2 digits), 67 (2 digits), and 8910 (4 digits) have even digit counts. Method 1: Using String Length Convert each number to a string and ...

Read More

Pick out numbers from a string in JavaScript

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

In JavaScript, extracting numbers from strings is a common task that can be efficiently accomplished using regular expressions and built-in string methods. This approach allows you to find and extract numeric values from mixed content. Understanding the Problem The goal is to extract all numeric values from a given string. For example, from the string "I am 25 years old and earn $1500.50", we want to extract [25, 1500.50]. This involves pattern matching to identify numeric sequences including integers and decimal numbers. Using Regular Expressions with match() ...

Read More

Smallest number of perfect squares that sums up to n in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 340 Views

We need to write a JavaScript function that finds the minimum number of perfect squares that sum up to a given positive number. The function should find a combination of perfect square numbers (1, 4, 9, 16, 25, ...) which when added gives the input number, using as few perfect squares as possible. Problem Example If the input number is 123: Input: 123 Output: 3 Because 123 = 121 + 1 + 1 (using three perfect squares: 11², 1², 1²) Understanding the Pattern This is a classic Dynamic Programming problem. We ...

Read More

2 Key keyboard problem in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 262 Views

In this problem, we start with a notepad containing one character 'A' and need to reach exactly 'n' characters using only two operations: Copy All and Paste. The goal is to find the minimum number of steps required. Problem Understanding Given a notepad with one 'A', we can perform: Copy All − Copy all characters currently on the notepad Paste − Paste the previously copied characters We need to find the minimum steps to get exactly 'n' A's on the notepad. Example Walkthrough For ...

Read More

Picking index randomly from array in JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 860 Views

In JavaScript, randomly selecting an index from an array is a common requirement for applications that need unpredictable behavior, such as shuffling content, random sampling, or creating dynamic user experiences. This article explores several effective methods to achieve this functionality. Problem Statement We need an efficient way to randomly select an index from a JavaScript array, where each index has an equal probability of being chosen. JavaScript doesn't provide a built-in method for this, so we'll implement our own solutions. Sample Input: Consider an array: let arr = [12, 45, 7, 89, 34, 56] Sample Output: ...

Read More

Calculating the area of a triangle using its three sides in JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 779 Views

In JavaScript, calculating the area of a triangle using its three sides can be accomplished through mathematical formulas. This is useful when you know the side lengths but not the height or base measurements. Problem Statement Create a JavaScript function that calculates the area of a triangle given the lengths of its three sides. Sample Input: Side A: 3 units Side B: 4 units Side C: 5 units Sample Output: Area: 6 Approach We'll explore two mathematical methods to solve this problem: ...

Read More
Showing 15101–15110 of 61,297 articles
Advertisements