Articles on Trending Technologies

Technical articles with clear explanations and examples

Accumulating some value over using a callback function and initial value in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 295 Views

We need to write a JavaScript function that takes an array, a callback function, and an initial value to accumulate values over array iteration, similar to Array.prototype.reduce(). Problem The goal is to create a custom reduce function that processes each array element through a callback function, accumulating a result from an initial value. Understanding Array Reduce The reduce method applies a callback function to each array element, building up a single result value. The callback receives the accumulator (previous result) and current element as parameters. Custom Reduce Implementation const arr = [1, 2, ...

Read More

Constructing a string based on character matrix and number array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 291 Views

We need to write a JavaScript function that takes an n × n matrix of string characters and an array of integers (positive and unique), then constructs a string from characters at the specified 1-based positions. Problem Understanding Given a character matrix, we flatten it into a single array and extract characters at positions specified by the number array (using 1-based indexing). Character Matrix: [ ['a', 'b', 'c', 'd'], ['o', 'f', 'r', 'g'], ['h', 'i', 'e', 'j'], ['k', 'l', 'm', 'n'] ] ...

Read More

Finding the most frequent word(s) in an array using JavaScript

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

In JavaScript, finding the most frequent words in an array is a common problem that involves counting occurrences and sorting by frequency. This article demonstrates how to find the top N most frequent words from an array of strings. Problem Statement We need to write a JavaScript function that takes an array of lowercase English strings and returns the most frequent elements. The function should: Accept an array of strings as the first parameter Accept a number specifying how many top frequent words to return Sort results by frequency (highest to lowest) For words with equal ...

Read More

How to create a canvas with not-allowed cursor on hover over objects using FabricJS?

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

In this article, we are going to create a canvas with a not-allowed cursor on hover using FabricJS. The not-allowed cursor is one of the native cursor styles available which can be used in FabricJS canvas. FabricJS provides various types of cursors like default, all-scroll, crosshair, col-resize, row-resize, etc., that reuse the native cursor under the hood. The hoverCursor property sets the style of the cursor when hovered over a canvas object. Syntax new fabric.Canvas(element, { hoverCursor: "not-allowed" }) Parameters element − This ...

Read More

How to set the border opacity of Rectangle while moving using FabricJS?

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

In this tutorial, we are going to set the border opacity of a Rectangle while moving using FabricJS. Rectangle is one of the various shapes provided by FabricJS. In order to create a rectangle, we will have to create an instance of fabric.Rect class and add it to the canvas. We can change the opacity of a rectangle while moving it around in the canvas by using the borderOpacityWhenMoving property. This property controls how transparent or opaque the selection border appears during the move operation. Syntax ...

Read More

How to return an object by parsing http cookie header in JavaScript?

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

Cookies are small pieces of data that are sent from a website to a user's web browser. They are used to store information about the user, such as their preferences or login status. When a user visits a website, their web browser will send a request to the server. The server will then send a response, which includes a set of headers. One of these headers is the "Cookie" header, which contains a list of all the cookies that are associated with the website. Understanding Cookie Headers Cookie headers can contain multiple name-value pairs separated by semicolons. ...

Read More

How to center a Text object horizontally on canvas using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 1K+ Views

In this tutorial, we are going to learn how to center a Text horizontally on canvas using FabricJS. We can display text on canvas by adding an instance of fabric.Text. Not only does it allow us to move, scale and change the dimensions of the text but it also provides additional functionality like text alignment, text decoration, line height which can be obtained by the properties textAlign, underline and lineHeight respectively. We can also center the text object horizontally on the canvas by using the centerH method. Syntax centerH() Example 1: Default Text Position ...

Read More

How many numbers in the given array are less/equal to the given value using the percentile formula in Javascript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 304 Views

In this article, you will understand how to calculate the percentile of a given value in an array using JavaScript. The percentile tells us what percentage of numbers in the array are less than or equal to a specific value. Percentile Formula We use the following formula to calculate the percentile: Percentile = (n/N) * 100 Where: n = count of values less than or equal to the given value N = total number of values in the array For values equal to our target, ...

Read More

Finding pandigital numbers using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 343 Views

A pandigital number is a number that contains all digits (0-9) at least once. In this tutorial, we'll create a JavaScript function to check if a given number string is pandigital. What is a Pandigital Number? A pandigital number must contain every digit from 0 to 9 at least once. For example, "1234567890" is pandigital, while "123456789" is not (missing 0). Example Let's implement a function to check if a number string is pandigital: const numStr1 = '47458892414'; const numStr2 = '53657687691428890'; const isPandigital = numStr => { let ...

Read More

How to convert square bracket object keys into nested object in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 877 Views

In JavaScript, objects with square bracket notation in their keys can be converted into properly nested objects. This is useful when dealing with flat data structures that represent nested relationships. Consider an object with square bracket notation: const flatObj = { "object[foo][bar][ya]": 100 }; console.log("Original object:", flatObj); Original object: { 'object[foo][bar][ya]': 100 } We want to convert this into a nested structure where each bracket represents a deeper level of nesting. Understanding the Problem The goal is to transform a key like "object[foo][bar][ya]" into a nested object structure: ...

Read More
Showing 15531–15540 of 61,298 articles
Advertisements