Articles on Trending Technologies

Technical articles with clear explanations and examples

JavaScript - How to create nested unordered list based on nesting of array?

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

In this tutorial, we'll learn how to create nested unordered lists in HTML using JavaScript. We'll use recursion to traverse nested arrays and generate the corresponding HTML structure dynamically. Understanding the Problem We need to convert a nested array structure into an HTML unordered list where: String elements become list items Array elements become nested sublists The structure preserves the original nesting levels For example: Coffee ...

Read More

Getting century from year in JavaScript

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

In JavaScript, determining the century from a given year is a common programming task. A century represents a period of 100 years, where the 1st century includes years 1-100, the 20th century covers 1901-2000, and so on. Understanding Century Calculation The key insight is that centuries don't align perfectly with hundreds. For example: Year 1900 belongs to the 19th century (not 20th) Year 2000 belongs to the 20th century (not 21st) Year 2001 begins the 21st century Logic and Algorithm To find the century from a year: Divide the year by 100 Round ...

Read More

Squared and square rooted sum of numbers of an array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 464 Views

Problem We are required to write a JavaScript function that takes in an array of numbers. Our function should take each number in the array and square it if it is even, or square root the number if it is odd and then return the sum of all the new numbers rounded to two decimal places. Example Following is the code − const arr = [45, 2, 13, 5, 14, 1, 20]; const squareAndRootSum = (arr = []) => { const res = arr.map(el => { ...

Read More

Binary subarrays with desired sum in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 164 Views

We need to write a JavaScript function that counts the number of subarrays in a binary array whose elements sum to a target value. Problem Statement Given a binary array arr and a target number, count all subarrays where the sum of elements equals the target. Example Input: const arr = [1, 0, 1, 0, 1]; const target = 2; Expected Output: 4 Explanation: The subarrays with sum 2 are: [1, 0, 1] (indices 0-2) [1, 0, 1] (indices 2-4) [0, 1, 0, 1] (indices 1-4) [1, 0, ...

Read More

How to create a canvas with not-allowed cursor using FabricJS?

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

In this article, we are going to create a canvas with a not-allowed cursor using FabricJS. A not-allowed cursor can be used to indicate that any action that has been requested, will not be carried out. not-allowed is one of the native cursor styles available which can be used in the FabricJS canvas too. FabricJS provides various types of cursors like default, all-scroll, crosshair, col-resize, row-resize etc. which are reusing the native cursor underhood. Each of these cursors look slightly different based on operating system. Syntax new fabric.Canvas(element: HTMLElement|String, { defaultCursor: String }: Object) ...

Read More

How to set the fill color of Ellipse using FabricJS?

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

In this tutorial, we are going to learn how we can change the appearance of an Ellipse object by changing its fill color using FabricJS. Ellipse is one of the various shapes provided by FabricJS. In order to create an ellipse, we will have to create an instance of fabric.Ellipse class and add it to the canvas. We can change the fill color by using the fill property which allows us to specify the color of the object's fill. Syntax new fabric.Ellipse({ fill: String }: Object) Parameters ...

Read More

How to set the background colour of selection of Textbox using FabricJS?

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

In this tutorial, we are going to learn how to set the background colour of selection of a Textbox using FabricJS. We can customize, stretch or move around the text written in a textbox. In order to create a textbox, we will have to create an instance of fabric.Textbox 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 Textbox by using the selectionBackgroundColor property. Syntax new fabric.Textbox(text: String, { selectionBackgroundColor : String}: Object) ...

Read More

How to change the font style of IText using FabricJS?

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

In this tutorial, we are going to learn about how to change the font style in IText object 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 ...

Read More

How to use Regex to get the string between curly braces using JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 6K+ Views

We can create a regular expression to find all substrings between curly braces and use methods like exec() or match() to extract them. In this tutorial, we will learn to use regular expressions to get strings between curly braces in JavaScript. For example, from the string 'This is a {string} with {curly} braces', we need to extract "string" and "curly". Using the exec() Method with Regular Expression The exec() method finds matched substrings and returns results in array format. It returns null if no matches are found. Syntax var regex = /{([^}]+)}/g; while (match ...

Read More

How many times can we sum number digits in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 201 Views

We are required to write a JavaScript function that takes in a positive integer and returns its additive persistence. The additive persistence of an integer, say n, is the number of times we have to replace the number with the sum of its digits until the number becomes a single digit integer. Example Walkthrough For example: If the number is: 1679583 Then we calculate: 1 + 6 + 7 + 9 + 5 + 8 + 3 = 39 // Pass 1 3 + 9 = 12 ...

Read More
Showing 14961–14970 of 61,297 articles
Advertisements