Articles on Trending Technologies

Technical articles with clear explanations and examples

Remove duplicates from array with URL values in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 490 Views

Suppose, we have an array of objects like this − const arr = [ { url: 'www.example.com/hello', id: "22" }, { url: 'www.example.com/hello', id: "22" }, { url: 'www.example.com/hello-how-are-you', id: ...

Read More

Most efficient method to groupby on an array of objects - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 334 Views

Grouping arrays of objects is a common task in JavaScript data processing. We'll explore efficient methods to group objects by single or multiple properties and aggregate values. Sample Data Let's start with an array of objects representing project phases, steps, and tasks: const arr = [ { Phase: "Phase 1", Step: "Step 1", Task: "Task 1", Value: "5" }, { Phase: "Phase 1", Step: "Step 1", Task: "Task 2", Value: "10" }, { Phase: "Phase 1", Step: "Step 2", Task: "Task 1", Value: "15" ...

Read More

Finding the product of array elements with reduce() in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 996 Views

We are required to write a JavaScript function that takes in an array and finds the product of all its elements using the reduce() method. Understanding reduce() for Products The reduce() method executes a reducer function on each array element, accumulating results into a single value. For multiplication, we start with an initial value of 1 and multiply each element. Syntax array.reduce((accumulator, currentValue) => { return accumulator * currentValue; }, 1); Example: Basic Product Calculation const arr = [3, 1, 4, 1, 2, -2, -1]; const ...

Read More

How to crop the top offset in a cloned image using FabricJS?

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

In this tutorial, we are going to learn how to crop the top offset in a cloned image using FabricJS. We can create an Image object by creating an instance of fabric.Image. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity etc. In order to crop the top offset in a cloned image, we use the top property. Syntax cloneAsImage( callback: function, { top: Number}: Object): fabric.Object Parameters callback (optional) − This parameter is a function which ...

Read More

Generating combinations from n arrays with m elements in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 826 Views

We are required to write a JavaScript function that generates combinations from n number of arrays with m number of elements in them. For example, consider this data: const arr = [ [0, 1], [0, 1, 2, 3], [0, 1, 2] ] We have 3 sub-arrays with different numbers of elements. What we want to do is get all combinations by selecting one item from each array. Understanding the Problem The goal is to generate a Cartesian product of multiple arrays. For the example ...

Read More

Get the smallest array from an array of arrays in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 554 Views

When working with nested arrays in JavaScript, you might need to find the smallest subarray based on the number of elements. This is useful for data processing, filtering operations, or when you need to identify the shortest path or sequence. Suppose we have a nested array of arrays like this: const arr = [ ["LEFT", "RIGHT", "RIGHT", "BOTTOM", "TOP"], ["RIGHT", "LEFT", "TOP"], ["TOP", "LEFT"] ]; console.log("Original array:", arr); Original array: [ [ 'LEFT', 'RIGHT', 'RIGHT', 'BOTTOM', 'TOP' ], ...

Read More

Encoding decimal to factorial and back in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 399 Views

The factorial number system uses factorials as bases instead of powers. Each digit position represents a factorial base, where the rightmost digit is base 0!, the next is base 1!, then base 2!, and so on. How Factorial Encoding Works In factorial representation, the nth digit from the right can range from 0 to n. For example: Position 0 (rightmost): 0 to 0, multiplied by 0! = 1 Position 1: 0 to 1, multiplied by 1! = 1 Position 2: 0 to 2, multiplied by 2! = ...

Read More

How to change an element's class with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 562 Views

In JavaScript, you can change an element's class using several methods. The most common approaches are using the className property for complete replacement and classList methods for more flexible manipulation. How to change the element's class using className property How to toggle between classes using className and classList Using className Property The className property allows you to get or set the entire class attribute of an element. When you assign a new value, it replaces all existing classes. Example ...

Read More

How to find a nearest higher number from a specific set of numbers: JavaScript ?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 189 Views

We have a set of numbers and our requirement is to find the same or the nearest higher number key to a specific number provided as the input to the function. The set of numbers is defined as: const numbers = { A: 107, B: 112, C: 117, D: 127, E: 132, F: 140, G: 117, H: 127, I: 132, J: 132, K: 140, ...

Read More

Returning the highest value from an array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 321 Views

We are required to write a JavaScript function that takes in an array of Numbers. Our function should iterate through the array and pick the greatest (largest) element from the array and return that element. Using a Custom Loop Function Here's a manual approach that iterates through the array to find the maximum value: const arr = [5, 3, 20, 15, 7]; const findGreatest = (arr = []) => { let greatest = -Infinity; if (!arr?.length) { return null; ...

Read More
Showing 14521–14530 of 61,297 articles
Advertisements