Articles on Trending Technologies

Technical articles with clear explanations and examples

How to set the background colour of selection of a Triangle using FabricJS?

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

In this tutorial, we are going to learn how to set the background colour of selection of a Triangle using FabricJS. Triangle is one of the various shapes provided by FabricJS. In order to create a triangle, we will have to create an instance of fabric.Triangle class and add it to the canvas. We can change an object's dimensions, rotate it or manipulate it when it is actively selected. We can change the background colour of selection of triangle by using the selectionBackgroundColor property. Syntax new fabric.Triangle({ selectionBackgroundColor : String }: Object) Parameters ...

Read More

How to create a chessboard pattern with JavaScript and DOM?

Imran Alam
Imran Alam
Updated on 15-Mar-2026 6K+ Views

Creating visual patterns with JavaScript and DOM manipulation is a great way to understand programming logic. In this tutorial, we'll create a classic chessboard pattern using JavaScript to dynamically generate alternating colored squares. Algorithm Overview The chessboard pattern relies on a simple mathematical principle: if the sum of row and column indices is even, the square is one color (black), otherwise it's another color (white). This creates the alternating pattern characteristic of a chessboard. Basic Implementation Here's how to create a chessboard pattern step by step: Create a container div for the chessboard Use ...

Read More

How to add animation in Line using FabricJS?

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

In this tutorial, we are going to learn how to add animation in Line using FabricJS. A Line element is one of the basic elements provided in FabricJS. It is used for creating straight lines. Because line elements are geometrically one-dimensional and do not contain an interior, they are never filled. We can create a line object by creating an instance of fabric.Line, specifying the x and y coordinates of the line and adding it to the canvas. In order to animate a line instance we use the animate method. Syntax animate(property: String | Object, value: Number ...

Read More

How to remove falsy values from an array in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 746 Views

In JavaScript, falsy values are values that evaluate to false in a boolean context. These include false, 0, "", null, undefined, and NaN. Removing falsy values from an array is a common operation that can be accomplished using several methods. What are Falsy Values? JavaScript has six falsy values that evaluate to false when used in boolean contexts: const falsyValues = [false, 0, "", null, undefined, NaN]; console.log("Falsy values:"); falsyValues.forEach(value => { console.log(`${value} is falsy:`, !value); }); Falsy values: false is falsy: true 0 is falsy: true is ...

Read More

How to check an element with specific id exist using JavaScript?

Aman Gupta
Aman Gupta
Updated on 15-Mar-2026 5K+ Views

In JavaScript, checking if an HTML element with a specific ID exists is a common task when manipulating the DOM. The document.getElementById() method returns the element if found, or null if not found. Syntax document.getElementById(id) document − The document object represents the HTML page loaded in the browser getElementById() − A method that searches for an element with the specified ID and returns it, or null if not found How It Works When document.getElementById() is called, it searches through the DOM tree to find an ...

Read More

How to convert a number into an array in JavaScript?

Prerna Tiwari
Prerna Tiwari
Updated on 15-Mar-2026 7K+ Views

In JavaScript, there are several methods to convert a number into an array of its individual digits. This conversion is useful for tasks like splitting phone numbers, parsing dates, or performing mathematical operations on individual digits. Method 1: Using split() Method The split() method is the simplest approach. It converts the number to a string and then splits it into individual characters. Example let number = 12345; let numberArray = number.toString().split(""); ...

Read More

Pairing an array from extreme ends in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 240 Views

We are required to write a JavaScript function that takes in an array of Number / String literals and returns another array of arrays. With each subarray containing exactly two elements, the nth element from start and nth from last. For example: If the array is − const arr = [1, 2, 3, 4, 5, 6]; Then the output should be − [[1, 6], [2, 5], [3, 4]] Example The code for this will be − const arr = [1, 2, 3, 4, 5, 6]; const edgePairs ...

Read More

JavaScript Group a JSON Object by Two Properties and Count

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

When working with JSON data, you often need to group objects by multiple properties and count occurrences. This is useful for data analysis, creating summaries, or generating reports from complex datasets. What is JSON? JSON (JavaScript Object Notation) is a lightweight data format for transferring data between systems. It uses key-value pairs where keys are strings and values can be various data types. Each entry is separated by commas, for example: {"name": "Peter", "age": 25}. const jsonData = [ { ...

Read More

isSubset of two arrays in JavaScript

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

In JavaScript, checking if one array is a subset of another means verifying that all elements of the second array exist in the first array. This is a common programming problem that can be solved efficiently using JavaScript's Set data structure. Understanding the Problem An array is considered a subset of another array if all its elements are present in the parent array. For example, [2, 4, 6] is a subset of [1, 2, 3, 4, 5, 6] because all elements (2, 4, 6) exist in the larger array. Using Set for Efficient Lookup The most ...

Read More

Checking for a Doubleton Number in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 372 Views

A "doubleton number" is a natural number that contains exactly two distinct digits. For example, 23, 35, 100, and 12121 are doubleton numbers because they each use only two different digits. Numbers like 123 (three digits) and 9980 (three digits: 9, 8, 0) are not doubleton numbers. Problem Statement We need to write a JavaScript function that takes a number and returns true if it's a doubleton number, false otherwise. Solution The approach is to convert the number to a string, track unique digits using an object, and check if exactly two distinct digits exist. ...

Read More
Showing 15411–15420 of 61,297 articles
Advertisements