Articles on Trending Technologies

Technical articles with clear explanations and examples

Grouping and sorting 2-D array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 930 Views

Suppose we have a two-dimensional array of numbers like this − const arr = [ [1, 3, 2], [5, 2, 1, 4], [2, 1] ]; We are required to write a JavaScript function that groups all the identical numbers into their own separate subarray, and then the function should sort the group array to place the subarrays into increasing order. Therefore, finally the new array should look like − const output = [ [1, 1, 1], [2, 2, ...

Read More

Get range of months from array based on another array JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 472 Views

Suppose we have two arrays of strings. The first array contains exactly 12 strings, one for each month of the year like this: const year = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec']; console.log(year); [ 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec' ] The second array contains exactly two strings, denoting a range of months like this: const monthsRange = ["aug", "oct"]; console.log(monthsRange); [ 'aug', 'oct' ] We need to ...

Read More

Remove duplicate items from an array with a custom function in JavaScript

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

In JavaScript, arrays often contain duplicate values that need to be removed. This article demonstrates how to create a custom function to eliminate duplicates and return an array with unique elements only. Understanding the Problem We need to create a function that accepts an array as input and returns a new array containing only unique items, excluding any duplicates. For example, given the array [0, 0, 2, 2, 3, 3], the function should return [0, 2, 3]. Algorithm Overview The algorithm iterates through the input array and adds items to a result array only if they ...

Read More

Converting array of arrays into an object in JavaScript

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

Converting an array of arrays into an object is a common task in JavaScript when dealing with key-value pair data. This is particularly useful when transforming data from APIs or CSV-like structures. Suppose we have an array of arrays that contains the performance of a cricket player like this: const arr = [ ['Name', 'V Kohli'], ['Matches', 13], ['Runs', 590], ['Highest', 183], ['NO', 3], ['SR', 131.5] ]; We need to write a JavaScript function that takes such ...

Read More

Finding all possible prime pairs that sum upto input number using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 620 Views

Problem We need to write a JavaScript function that takes a number n and returns an array of all prime number pairs that sum to n. Both numbers in each pair must be prime numbers. Understanding Prime Numbers A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. For example: 2, 3, 5, 7, 11, 13, 17, 19, 23. Algorithm Approach The solution involves three main steps: Create a function to check if a number is prime Generate all possible prime numbers up to ...

Read More

How to lock the vertical scaling of a Circle using FabricJS?

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

In this tutorial, we are going to learn how to lock the vertical scaling of a Circle using FabricJS. Just as we can specify the position, colour, opacity and dimension of a circle object in the canvas, we can also specify whether we want to stop scaling an object vertically. This can be done by using the lockScalingY property. Syntax new fabric.Circle({ lockScalingY: Boolean }) Parameters options (optional) − This parameter is an Object which provides additional customizations to our circle. Using this ...

Read More

How to lock the horizontal skewing of Triangle using FabricJS?

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

In this tutorial, we are going to learn how to lock the horizontal skewing of a Triangle using FabricJS. Just as we can specify the position, colour, opacity and dimension of a triangle object in the canvas, we can also specify whether we want to stop skewing an object horizontally. This can be done by using the lockSkewingX property. Syntax new fabric.Triangle({ lockSkewingX : Boolean }: Object) Parameters Options (optional) − This parameter is an Object which provides additional customizations to our triangle. ...

Read More

How to insert characters in IText using FabricJS?

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

In this tutorial, we are going to learn about how to insert characters in IText using FabricJS. The IText class was introduced in FabricJS version 1.4, extends fabric.Text and is used to create IText instances. An IText instance gives us the freedom to select, cut, paste or add new text without additional configurations. There are also various supported key combinations and mouse/touch combinations which make text interactive which are not provided in Text. Textbox, however, which is based on IText allows us to resize the text rectangle and wraps lines automatically. This is not true for IText as height ...

Read More

How to calculate and print bonus and gross using basic salary by JavaScript?

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

We will first determine the bonus percentage by multiplying the basic salary by a certain percentage. Next, we will calculate the bonus amount by multiplying the bonus percentage with the basic salary. Finally, we will add the bonus amount to the basic salary to determine the gross salary and print all three values. Here is an example of how to calculate and print the bonus and gross salary using the basic salary in JavaScript − Basic Example // Declare basic salary variable var basicSalary = 5000; // Calculate bonus (10% of basic salary) var bonus ...

Read More

How to sort array according to age in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 476 Views

We are required to write a JavaScript function that takes in an array of numbers representing ages of some people. Then the function should bring all the ages less than 18 to the front of the array without using any extra memory. Understanding the Problem We need to sort an array so that all minors (ages < 18) appear before adults (ages ≥ 18), while maintaining the original order within each group. Example The code for this will be − const ages = [23, 56, 56, 3, 67, 8, 4, 34, 23, 12, ...

Read More
Showing 15241–15250 of 61,297 articles
Advertisements