Articles on Trending Technologies

Technical articles with clear explanations and examples

How to create an array of partial objects from another array in JavaScript?

Tarun Singh
Tarun Singh
Updated on 15-Mar-2026 11K+ Views

Arrays are one of the most commonly used data types in JavaScript. They are used to store collections of data and allow for efficient access and manipulation of data. Arrays can contain any type of data, including primitive values, objects, and even other arrays. The technique of creating an array of partial objects from an array is a valuable technique when dealing with complex data sets. Partial objects contain only a subset of the data from the original array, allowing us to focus on a particular set of data. This can be especially useful when dealing with large data ...

Read More

Reorder an array in JavaScript

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 10K+ Views

Reordering an array means changing the sequence of elements within the array. JavaScript provides several built-in methods to reorder arrays, each serving different purposes. Using sort() for Alphabetical Ordering The sort() method sorts array elements alphabetically in ascending order by default. It modifies the original array. const states = ["Telangana", "Uttar Pradesh", "Karnataka", "Kerala", "TamilNadu"]; document.getElementById("para1").innerHTML = "Original: " + states; states.sort(); ...

Read More

How to split comma and semicolon separated string into a two-dimensional array in JavaScript ?

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

Let's say we have a variable "users" that contains the following string of text where each user is separated by a semicolon and each attribute of each users is separated by a comma − const users = 'Bob, 1234, Bob@example.com;Mark, 5678, Mark@example.com'; We are required to write a JavaScript function that takes in one such string and splits this into a multidimensional array that looks like this − const arr = [ ['Bob', 1234, 'Bob@example.com'], ['Mark', 5678, 'Mark@example.com'] ]; Method 1: Using split() and for Loop ...

Read More

Given an array of integers, find the pair of adjacent elements that has the largest product and return that product JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 2K+ Views

Finding the pair of adjacent elements with the largest product is a common array problem in JavaScript. This involves iterating through the array and comparing products of consecutive elements. Problem Understanding Given an array of integers, we need to find two adjacent elements whose product is maximum among all possible adjacent pairs. For example, in array [1, 2, 3, 4], the adjacent pairs are (1, 2), (2, 3), and (3, 4) with products 2, 6, and 12 respectively. Method 1: Using -Infinity for Initialization This approach initializes the maximum product with -Infinity to handle arrays with ...

Read More

Tribonacci series in JavaScript

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

The tribonacci sequence is a generalization of the Fibonacci sequence where each term is the sum of the three preceding terms. Unlike Fibonacci which uses two preceding terms, tribonacci uses three. The standard tribonacci series starts with 0, 1, 1, and each subsequent term is the sum of the previous three terms: 0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149... How It Works Each term after the first three follows the formula: T(n) = T(n-1) + T(n-2) + T(n-3) Where T(0) = 0, T(1) = 1, T(2) = 1 ...

Read More

Crack Alphabets fight problem in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 263 Views

Problem Consider a situation where armies of two teams of alphabets are fighting each other. Each soldier has a specific weight based on their letter: Team A (Positive Weights) Soldier Weight A ...

Read More

How to lock the vertical movement of Ellipse using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 288 Views

In this tutorial, we are going to learn how to lock the vertical movement of an Ellipse using FabricJS. Just as we can specify the position, color, opacity and dimension of an ellipse object in the canvas, we can also specify whether we want it to move only in the X-axis. This can be done by using the lockMovementY property. Syntax new fabric.Ellipse({ lockMovementY: Boolean }: Object) Parameters options (optional) − This parameter is an Object which provides additional customizations to our ellipse. ...

Read More

Squared concatenation of a Number in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 351 Views

We are required to write a JavaScript function that takes in a number and returns a new number in which all the digits of the original number are squared and concatenated. For example: If the number is − 99 Then the output should be − 8181 because 9² is 81 and 9² is 81, so concatenating them gives 8181. Example Let's implement this function step by step: const num = 9119; const squared = num => { const numStr = String(num); ...

Read More

Finding the least common multiple of a range of numbers in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 444 Views

We are required to write a JavaScript function that takes in an array of exactly two numbers specifying a range. The function should then calculate the least common multiple of all the numbers within that range and return the final result. Understanding LCM and GCD To find the LCM of multiple numbers, we first need helper functions for GCD (Greatest Common Divisor) and LCM of two numbers: GCD: The largest number that divides both numbers evenly LCM: The smallest positive number that is divisible by both numbers Formula: LCM(a, b) = (a × b) / ...

Read More

Checking if a number is some power of the other JavaScript

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

In this problem statement, our objective is to check if a given input number is some power of another number using JavaScript functionalities. Logic for the Problem To determine if a number a is a power of another number b, we can use logarithms. If a = b^n for some integer n, then log_b(a) = n should be an integer. Since JavaScript's Math.log() returns the natural logarithm, we use the change of base formula: log_b(a) = ln(a) / ln(b). If this result is an integer, then a is a power of b. Algorithm Step 1 ...

Read More
Showing 14741–14750 of 61,299 articles
Advertisements