Articles on Trending Technologies

Technical articles with clear explanations and examples

How to make a setInterval() stop after some time or after a number of actions in JavaScript?

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

The setInterval() function repeatedly executes code at specified intervals. To stop it after some time or a number of actions, use clearInterval() with conditions. Method 1: Stop After Time Duration This example stops the interval after 10 seconds: Stop setInterval After Time var startTime = new Date().getTime(); ...

Read More

Sorting an array by date in JavaScript

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

Sorting an array by date in JavaScript is a common task when working with arrays of objects containing date information. This article shows how to sort objects by their date properties using JavaScript's built-in sorting methods. The Problem Suppose we have an array of objects like this: const arr = [ {id: 1, date: 'Mar 12 2012 10:00:00 AM'}, {id: 2, date: 'Mar 8 2012 08:00:00 AM'} ]; We need to sort this array according to the date property of each object, either newest first ...

Read More

Parse and balance angle brackets problem in JavaScript

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

In JavaScript, determining whether angle brackets in a string are properly balanced is a common problem when working with HTML, XML, or template parsing. This problem requires checking that every opening angle bracket '' in the correct order. What is a Stack-based Approach? The stack-based approach uses a Last In, First Out (LIFO) data structure to track opening brackets. When we encounter an opening bracket, we push it onto the stack. When we find a closing bracket, we check if there's a matching opening bracket at the top of the stack and pop it if found. Think ...

Read More

Finding the largest non-repeating number in an array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 452 Views

In JavaScript, finding the largest non-repeating number in an array requires tracking element frequencies and identifying unique values. This problem becomes efficient when we know the value range constraints. We need to write a function that takes an array of integers and returns the largest number that appears exactly once. If no unique number exists, return -1. The constraint given is that all array elements satisfy: 0 < arr[i] < 101 This means all values are between 1 and 100, inclusive. Example Input and Output For the input array: const ...

Read More

Converting humanYears into catYears and dogYears in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 370 Views

We need to write a JavaScript function that converts human age into equivalent cat and dog years. The conversion follows specific aging rules for the first two years, then a constant rate afterward. Problem Statement Create a function that takes human age in years and returns an array containing human years, cat years, and dog years. Input: const humanYears = 15; Expected Output: [15, 76, 89] Age Conversion Rules The aging calculation follows these rules: Year 1: Both cats and dogs age ...

Read More

Summing numbers present in a string separated by spaces using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 710 Views

We are required to write a JavaScript function that takes in a string which has integers inside it separated by spaces. The task of our function is to convert each integer in the string into an integer and return their sum. Problem Given a string containing numbers separated by spaces, we need to: Split the string into individual number strings Convert each string to a number Calculate the sum of all numbers Method 1: Using split() and reduce() const str = '1 5 ...

Read More

How to disable the interactivity of canvas using FabricJS?

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

In this article, we are going to learn how to disable the interactivity of canvas in FabricJS. The interactive layer on top of each object is one of the unique features of FabricJS. As soon as we initialize a canvas, it's possible to select the objects, drag them around or manipulate a group selection. However, all this can be undone by assigning the interactive property to False. Syntax new fabric.Canvas(element: HTMLElement|String, { interactive : Boolean }: Object) Parameters element − This parameter is ...

Read More

JavaScript: How to check if a number is even without using the modulo operator?

Shriansh Kumar
Shriansh Kumar
Updated on 15-Mar-2026 1K+ Views

For a given integer number, write a program in JavaScript to check whether a number is odd or even and return the same to the user. It's pretty easy to check whether a number is even by using the modulo operator. But, in this article, we will be checking whether a number is even or not without using the modulo operator. Using the For Loop In this approach, we are going to use the for loop to check whether a number is even or not. The idea is to take a Boolean flag variable as true and toggle ...

Read More

How to set the style of controlling corners of a Circle using FabricJS?

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

In this tutorial, we are going to learn how to set the style of controlling corners of Circle using FabricJS. Circle is one of the various shapes provided by FabricJS. In order to create a circle, we will have to create an instance of fabric.Circle class and add it to the canvas. The controlling corners of an object allow us to scale, stretch or change its position. We can customize our controlling corners in many ways such as adding a specific colour to it, changing its size etc. We can change the style by using the cornerStyle property. ...

Read More

How to set the horizontal scale factor of a Rectangle using FabricJS?

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

In this tutorial, we are going to learn how to set the horizontal scale factor of a Rectangle 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. Just as we can specify the position, colour, opacity and dimension of a rectangle object in the canvas, we can also set the horizontal scale of a rectangle object. This can be done by using the scaleX property. Syntax new fabric.Rect({ scaleX : Number ...

Read More
Showing 15691–15700 of 61,297 articles
Advertisements