Breaking a string into chunks of defined length and removing spaces using JavaScript

AmitDiwan
Updated on 15-Mar-2026 23:19:00

339 Views

We are required to write a JavaScript function that takes in a string sentence that might contain spaces as the first argument and a number as the second argument. Our function should first remove all the spaces from the string and then break the string into a number of chunks specified by the second argument. All the string chunks should have the same length with an exception of last chunk, which might, in some cases, have a different length. Solution Approach The solution involves two main steps: Remove all spaces using ... Read More

decipher.update() Method in Node.js

Mayank Agarwal
Updated on 15-Mar-2026 23:19:00

487 Views

The decipher.update() method is used to decrypt encrypted data incrementally in Node.js. It processes encrypted data according to specified encoding formats and is part of the Decipher class within the crypto module. Syntax decipher.update(data, [inputEncoding], [outputEncoding]) Parameters data – The encrypted data to be decrypted. Can be a string or Buffer depending on inputEncoding. inputEncoding – (Optional) The encoding of the input data. Common values: 'hex', 'base64'. If omitted, data is treated as a Buffer. outputEncoding – (Optional) The encoding for ... Read More

Creating Animated Counter using HTML, CSS, and JavaScript

Mayank Agarwal
Updated on 15-Mar-2026 23:19:00

19K+ Views

An animated counter is a display that smoothly transitions from one number to another, typically starting from 0 and counting up to a target value. This creates an engaging visual effect commonly used in dashboards, statistics displays, and landing pages. In this article, we'll create an animated counter using HTML for structure, CSS for styling, and JavaScript for the animation logic. Steps for Creating Animated Counter Follow these steps to build the animated counter: Create two div elements: one container for styling and one to display the counter value. ... Read More

How to create a Rectangle with help cursor on hover over objects using FabricJS?

Rahul Gurung
Updated on 15-Mar-2026 23:19:00

249 Views

In this tutorial, we are going to create a Rectangle with a help cursor on hover over objects using FabricJS. "help" is one of the native cursor styles available which can be used in the FabricJS canvas too. FabricJS provides various types of cursors such as default, all-scroll, crosshair, col-resize, row-resize, etc., that actually 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.Rect({ hoverCursor: String }: Object) Parameters ... Read More

Logging HTTP Requests and Errors using Morgan.js

Mukul Latiyan
Updated on 15-Mar-2026 23:19:00

2K+ Views

Morgan is a middleware for Node.js that simplifies HTTP request logging in Express applications. It automatically captures and formats request information, eliminating the need to write custom logging code manually. Morgan helps gather logs from your server and prepares them for analysis. It provides many predefined formats and customization options, making it suitable for both small and large projects. Installing Morgan Install Morgan using npm: npm install morgan Then import it into your application: const morgan = require('morgan') Basic Usage Example Here's a simple Express application using Morgan ... Read More

How to Create Horizontal and Vertical Tabs using JavaScript?

Rushi Javiya
Updated on 15-Mar-2026 23:19:00

1K+ Views

We can create tabs using HTML, CSS & JavaScript. There can be two types of tabs. One is horizontal tabs, and another is vertical tabs. The tabs allow us to show different contents in very less space as we can show the different content according to the different tabs. We will learn to create horizontal and vertical tabs from scratch using HTML, CSS, and JavaScript. Create Horizontal Tabs We can show all tabs in a single row by creating horizontal tabs. Also, we can show the content of the selected tab below all tabs. Syntax ... Read More

Finding deviations in two Number arrays in JavaScript

AmitDiwan
Updated on 15-Mar-2026 23:19:00

198 Views

We are required to write a JavaScript function that takes in two number arrays and returns the elements that are not common to both arrays (symmetric difference). For example, if the two arrays are: const arr1 = [2, 4, 2, 4, 6, 4, 3]; const arr2 = [4, 2, 5, 12, 4, 1, 3, 34]; Then the output should be: [6, 5, 12, 1, 34] Method 1: Using indexOf() Method This approach uses nested loops to check if elements exist in the other array: const arr1 = [2, ... Read More

What happens when length of object is set to 0 - JavaScript?

AmitDiwan
Updated on 15-Mar-2026 23:19:00

446 Views

In JavaScript, setting an array's length property to 0 immediately removes all elements and clears the array. This is an efficient way to empty an array without creating a new one. Initial Array Example Let's start with an array containing some elements: var arrayObject = [ "John", "David", "Mike" ]; console.log("Original array:", arrayObject); console.log("Original length:", arrayObject.length); Original array: [ 'John', 'David', 'Mike' ] Original length: 3 Setting Length to 0 When you set length = 0, ... Read More

Take in array of objects and convert the above JSON to a Tree-structure in JavaScript

AmitDiwan
Updated on 15-Mar-2026 23:19:00

2K+ Views

In web development, you often need to convert flat arrays of hierarchical data into tree structures. This is common when working with organizational charts, file systems, or nested menus. Input Data Structure Suppose we have an array of objects representing parent-child relationships: const arr = [ { "parentIndex": '0', "childIndex": '3', "parent": "ROOT", "child": "root3" }, ... Read More

Finding the longest common consecutive substring between two strings in JavaScript

AmitDiwan
Updated on 15-Mar-2026 23:19:00

1K+ Views

We are required to write a JavaScript function that takes in two strings. Let's call them str1 and str2. The function should then find out the longest consecutive string that is common to both the input strings and return that common string. For example − If the input strings are − const str1 = 'ABABC'; const str2 = 'BABCA'; Then the output string should be − const output = 'BABC'; How It Works This problem uses dynamic programming to build a 2D matrix where each cell [i][j] represents the ... Read More

Advertisements