Articles on Trending Technologies

Technical articles with clear explanations and examples

Longest string with two distinct characters in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 506 Views

We need to write a JavaScript function that finds the longest substring containing at most two distinct characters. The function takes a string as input and returns the length of the longest valid substring. For example, if the input string is 'kjeljsdl', the longest substring with at most 2 distinct characters is 'jljl' with length 4. Understanding the Problem A substring with at most two distinct characters means we can have: Only one character repeated: "aaa" Two different characters in any combination: "abab", "aabb" Sliding Window Approach The most efficient solution uses a ...

Read More

How to create a canvas with a help cursor using FabricJS?

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

In this article, we are going to create a canvas with a help cursor using FabricJS. The question mark in a help pointer indicates that useful information for the user is present. It is also often accompanied by useful links and can be seen while using a new application. help is one of the native cursor style 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., that reuse the native cursor under the hood. Each of these cursors look slightly different based on operating system. ...

Read More

How to set the height of an Ellipse using FabricJS?

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

In this tutorial, we are going to learn how to set the height of an Ellipse using FabricJS. Ellipse is one of the various shapes provided by FabricJS. In order to create an ellipse, we will create an instance of fabric.Ellipse class and add it to the canvas. We can manipulate an ellipse object by changing its position, opacity, stroke and also its dimension. FabricJS allows us to control an object's dimensions by using the width and height properties. Syntax new fabric.Ellipse({ height: Number }: Object) Parameters ...

Read More

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

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

In this tutorial, we are going to set the border opacity of a Textbox while moving 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 the opacity of the border of a textbox while moving it around in the canvas by using the borderOpacityWhenMoving property. Syntax new fabric.Textbox(text: String, { borderOpacityWhenMoving: Number }: Object) Parameters text − This parameter accepts a String ...

Read More

FabricJS – How to get the image element on which the current instance is based on?

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

In this tutorial, we are going to learn how to get the image element on which the current instance is based on using FabricJS. We can create an Image object by creating an instance of fabric.Image. 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 get the image element on which the current instance is based on, we use the getElement method. Syntax getElement(): HTMLImageElement Using the getElement Method In this example, we have used the getElement ...

Read More

Explain the Scope and Scope Chain in JavaScript

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

In JavaScript, the scope defines how and in which part of our code we can access the variables and functions. In simple terms, the scope helps us improve our code's security and readability. So, we can access the variables and functions only inside its scope but not outside. We will discuss multiple types of scopes in this tutorial. Global Scope in JavaScript The variables and functions defined globally mean outside all blocks and functions with global scope. We can access all variables and functions with the global scope anywhere inside our code. Syntax Users can ...

Read More

How to convert Object's array to an array using JavaScript?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 9K+ Views

Converting an array of objects to a flat array is a common task in JavaScript. There are several approaches to extract all values from objects and create a single array containing those values. Let's understand the problem with an example: Given Array of Objects: let carObj = [ { name: "John", car: "Ford" }, { name: "Mark", car: "BMW" }, { name: "Ben", car: "Toyota" } ] Expected Output: ["John", "Ford", "Mark", "BMW", "Ben", "Toyota"] There are multiple ways to achieve this conversion: ...

Read More

How to use Selenium Web Driver and JavaScript to Login any website?

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

Nowadays, automation is very useful for testing applications. Many automation tools are available, and Selenium is one of them, developed in 2004. Also, it is a cross-platform tool, so we can use Selenium with most programming languages, and here we will use it with JavaScript. Users need to create a Node.js application to use the Selenium WebDriver with JavaScript. Setting Up Node.js Application Follow these steps to create a Node.js application for Selenium automation: Step 1: Initialize a new Node.js project npm init -y Step 2: Install the Selenium WebDriver package ...

Read More

Removing Negatives from Array in JavaScript

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 2K+ Views

In JavaScript, you often need to remove negative values from an array. This article shows three effective methods to accomplish this task. Input-Output Scenarios Let's look at typical scenarios. When an array contains both negative and positive values, we need to filter out the negatives: Input = [-2, 5, -7, 32, 78, -32] Output = [5, 32, 78] If the array contains only positive values, it remains unchanged: Input = [56, 43, 12, 67, 69, 34] Output = [56, 43, 12, 67, 69, 34] Using the filter() Method (Recommended) ...

Read More

Count number of entries in an object having specific values in multiple keys JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 399 Views

In JavaScript, you often need to count objects in an array that match specific criteria across multiple properties. This is commonly done using the filter() method combined with conditional logic. Suppose we have an array of objects representing trade data: const arr = [ {"goods":"Wheat", "from":"GHANA", "to":"AUSTRALIA"}, {"goods":"Wheat", "from":"USA", "to":"INDIA"}, {"goods":"Wheat", "from":"SINGAPORE", "to":"MALAYSIA"}, {"goods":"Wheat", "from":"USA", "to":"INDIA"}, ]; We need to count objects where the "from" property equals "USA" and the "to" property equals "INDIA". Using filter() and length ...

Read More
Showing 14991–15000 of 61,299 articles
Advertisements