Articles on Trending Technologies

Technical articles with clear explanations and examples

How to make a polygon object react to the drag and drop event using FabricJS?

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

We can create a Polygon object by creating an instance of fabric.Polygon. A polygon object can be characterized by any closed shape consisting of a set of connected straight line segments. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity etc. We use the event:dragover and event:drop events to make a polygon object react to the drag and drop event. Syntax object.on('drop', function(event) { // Handle drop event }); object.on('dragover', function(event) { // Handle dragover ...

Read More

JavaScript - Create an alert on clicking an HTML button

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 5K+ Views

In this article, we will learn to create an alert by clicking an HTML button in JavaScript. JavaScript is extensively utilized to increase user interactions on web pages. One of the widespread usage scenarios is to display an alert on a button click. What is an Alert in JavaScript? An alert is a built-in JavaScript function that displays a small pop-up or a dialogue box window containing a message. The syntax for using an alert is: alert("Your message here"); This function pauses the execution of the script until the user dismisses the alert ...

Read More

Generate all combinations of supplied words in JavaScript

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

In JavaScript, there are scenarios where you may need to generate every possible combination of a string's characters. This can be especially useful in areas like cryptography, analyzing subsets of data, or solving problems involving permutations. In this article, we'll learn to implement a JavaScript function to achieve this task. Generate all combinations of supplied words Following are the different approaches for generating all combinations of supplied words − Recursive Approach Iterative Approach Using Bitmasking Using Recursive Approach The recursive approach builds combinations by including ...

Read More

Grouping an Array and Counting items creating new array based on Groups in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 415 Views

When working with arrays of objects in JavaScript, you often need to group data by specific properties and count unique items. This article demonstrates how to group an array by region and count unique users per region. Problem Statement Suppose we have an array of objects representing user data across different regions: const arr = [ { region: "Africa", fruit: "Orange", user: "Gary" }, { region: "Africa", fruit: "Apple", user: "Steve" }, { region: "Europe", fruit: "Orange", user: "John" }, ...

Read More

Deriving Random10() function from Random7() in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 339 Views

Suppose we have a random7() function that generates random numbers from 1 to 7. We need to create a random10() function that generates random numbers from 1 to 10, using only the random7() function. Problem const random7 = () => Math.ceil(Math.random() * 7); This function yields a random number between 1 and 7 (inclusive) every time we call it. We need to write a random10() function that returns random numbers between 1 and 10 (inclusive) using only this random7() function. Using Rejection Sampling (Optimal Solution) The most efficient approach uses rejection sampling. We ...

Read More

FabricJS – Applying scale multiplier to a Polygon converted to a HTMLCanvasElement

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

We can create a Polygon object by creating an instance of fabric.Polygon. A polygon object can be characterized by any closed shape consisting of a set of connected straight line segments. 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 convert a polygon object into HTMLCanvasElement we use the toCanvasElement method. It returns the DOM element of type HTMLCanvasElement, an interface which inherits its properties and methods from the HTMLElement interface. We use the multiplier property to set a multiplier to the ...

Read More

10 Interesting things you can do with a few lines of JavaScript

Rushi Javiya
Rushi Javiya
Updated on 15-Mar-2026 366 Views

In this tutorial, let us discuss some fascinating things that a few lines of JavaScript can do. Almost every website uses JavaScript. JavaScript was born in 1995, and it is a programming language similar to other languages, but it runs faster because it doesn't have many predefined functions. JavaScript can create programs, libraries, and scripts for websites or desktop applications. A lot of web developers are also good at writing JavaScript. Some JavaScript codes are fascinating if you observe how it behaves. Let us discuss what are these fascinating things in JavaScript. 1. Fascinating Things About Semicolons ...

Read More

Compare the Triplets - JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 231 Views

The "Compare the Triplets" problem is a popular algorithmic challenge where you compare two arrays of three integers each and count how many comparisons each array wins. Alice and Bob each have three scores, and we need to determine who wins more individual comparisons. Problem Statement Given two triplets (arrays of 3 elements each), compare corresponding elements and award points: 1 point to Alice if her element is greater, 1 point to Bob if his element is greater, 0 points for ties. Return an array with [Alice's score, Bob's score]. Example Input Alice: [5, 6, ...

Read More

Add matching object values in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 445 Views

In JavaScript, you can add matching object values by iterating through an array of objects and accumulating values for common keys. This is useful for aggregating data from multiple objects. Consider an array of objects like this: const arr = [{a: 2, b: 5, c: 6}, {a: 3, b: 4, d: 1}, {a: 1, d: 2}]; console.log("Input array:", arr); Input array: [ { a: 2, b: 5, c: 6 }, { a: 3, b: 4, d: 1 }, { a: 1, d: 2 } ] Each object has unique properties within itself, ...

Read More

Filter unique array values and sum in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 784 Views

In JavaScript, you may need to filter arrays that contain duplicate values and combine their numeric values. This is common when processing data like product orders, transactions, or inventory records. Problem Statement Given an array of arrays where each subarray has three elements [id, name, amount], we need to: Remove duplicate entries based on the first element (id) Sum the third element (amount) for matching entries const arr = [[12345, "product", "10"], [12345, "product", "15"], [1234567, "other", "10"]]; The expected output should combine the duplicate entries and sum their amounts: ...

Read More
Showing 14421–14430 of 61,297 articles
Advertisements