Articles on Trending Technologies

Technical articles with clear explanations and examples

How to include Text object's default values in its serialization using FabricJS?

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

In this tutorial, we are going to learn how to include Text object's default values in its serialization 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 we can also add additional functionalities. Serialization is used in order to export canvas contents. In order to achieve this we use toObject() and toJSON() methods. The includeDefaultValues property allows us to include or omit the object's default values when being serialized. Syntax new fabric.Text(text: String, { includeDefaultValues: ...

Read More

Validating a Form with Parsley.js

Mukul Latiyan
Mukul Latiyan
Updated on 15-Mar-2026 2K+ Views

In this tutorial, we will show how you can use Parsley.js, which is a JavaScript library that is mainly used to validate forms. Parsley helps in validating the forms in a very subtle and easy manner, and it is one of the widely used form validation libraries out there. Features of Parsley.js There are plenty of reasons why Parsley is a good choice for validating your JavaScript forms. Some of them are mentioned below. Intuitive DOM API − The DOM API allows you ...

Read More

Swapping adjacent words of a String in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 558 Views

In JavaScript, swapping adjacent words in a string means exchanging pairs of words - the first word with the second, the third with the fourth, and so on. If there's an odd number of words, the last word remains in its position. Example Here's how to swap adjacent words using the reduce method: const str = "This is a sample string only"; const replaceWords = str => { return str.split(" ").reduce((acc, val, ind, arr) => { if(ind % 2 === 1){ ...

Read More

Sorting an array that contains undefined in JavaScript?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 3K+ Views

In JavaScript, arrays can contain undefined values which require special handling during sorting. By default, the sort() method converts all elements to strings, placing undefined values at the end of the sorted array. Let's explore different approaches to sort arrays containing undefined values effectively. Default Behavior with sort() When using the basic sort() method on arrays with undefined, JavaScript automatically places undefined values at the end: var namearr = ["Zebra", "Yatch", undefined, "Egg", undefined]; namearr.sort(); ...

Read More

Count by unique key in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 696 Views

When working with arrays of objects, you often need to count occurrences based on unique key values. This is particularly useful for data analysis, grouping records, or creating summary statistics. The Problem Given an array of objects with nested properties, we want to count how many times each unique user appears: const arr = [ { assigned_user: { name: 'Paul', ...

Read More

Finding all the unique paths in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 308 Views

In a grid navigation problem, we need to find the number of unique paths from the top-left corner (0, 0) to the bottom-right corner (m-1, n-1) of an m×n grid, where movement is restricted to only right or down directions. This is a classic dynamic programming problem. Each cell's value represents the number of ways to reach that position from the starting point. Algorithm Explanation The solution uses dynamic programming with these key principles: First row and first column have only 1 path each (straight line) For any other cell, paths = paths from above ...

Read More

Calculating 1s in binary representation of numbers in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 530 Views

We need to write a JavaScript function that takes an integer num and returns an array where each element represents the count of 1s in the binary representation of numbers from 0 to num. Problem Given a number num, create an array where: Index i contains the count of 1s in binary representation of i Array includes elements for numbers 0 through num (inclusive) For example, if num = 4: Input: 4 Output: [0, 1, 1, 2, 1] Output Explanation Let's break down the binary representations: Number ...

Read More

Constructing an array of first n multiples of an input number in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 420 Views

We are required to write a JavaScript function that takes in two numbers, let say m and n. Our function should construct and return an array of first n natural multiples of m. Problem Statement Given two numbers m and n, we need to create a function that returns an array containing the first n multiples of m. For example, if m = 6 and n = 5, the function should return [6, 12, 18, 24, 30]. Method 1: Using a For Loop The most straightforward approach is to use a for loop to iterate ...

Read More

crypto.scrypt() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 884 Views

The crypto.scrypt() method provides an asynchronous implementation of the scrypt password-based key derivation function. Scrypt is designed to be computationally expensive and memory-intensive, making it resistant to brute-force attacks by requiring significant resources to compute. Syntax crypto.scrypt(password, salt, keylen, [options], callback) Parameters The parameters are described below: password – The password to derive a key from. Can be a string, Buffer, TypedArray, or DataView. ...

Read More

How to create a Rectangle with border colour using FabricJS?

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

In this tutorial, we are going to create a Rectangle with border colour 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. Since FabricJS is extremely flexible, we are allowed to customize our rectangle object in any way we like. One of the properties that FabricJS provides is borderColor which allows us to manipulate the colour of the border when our object is active. Syntax new fabric.Rect({ borderColor: String }: Object) ...

Read More
Showing 16001–16010 of 61,297 articles
Advertisements