Articles on Trending Technologies

Technical articles with clear explanations and examples

FabricJS – How to set Polygon objects properties using function instead of constructor?

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

We can create a Polygon object by creating an instance of fabric.Polygon. A polygon object can be characterized by any closed shape consisting of a set of connected straight line segments. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity etc. Syntax set(key: String, value: String | Boolean | Number | Object | Function) Parameters key − This parameter accepts a String which specifies the property we ...

Read More

How to align images on a card with a dynamic title in Javascript?

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

Aligning images on a card with dynamic titles in JavaScript involves using CSS for layout and JavaScript for dynamic content updates. This creates responsive, interactive card components commonly used in modern web applications. Approach Create a card container using a div or section element with appropriate CSS classes. Add a header element for the dynamic title with a unique class or ID for styling and JavaScript targeting. Include an image element within the card container using the img tag or background image. Use CSS Flexbox properties like display: flex, justify-content, and align-items to control alignment. Apply responsive ...

Read More

Removing first k characters from string in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 266 Views

We are required to write a JavaScript function that takes in a string and a number, say k and returns another string with first k characters removed from the string. For example: If the original string is − const str = "this is a string" and, n = 4 then the output should be − const output = " is a string" Method 1: Using substr() Method The substr() method extracts characters from a string starting at a specified position. const str = 'this ...

Read More

Expanding Numerals in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 225 Views

We are required to write a function that, given a number, say, 123, will output an array − [100, 20, 3] Basically, the function is expected to return an array that contains the place value of all the digits present in the number taken as an argument by the function. Understanding Place Values Each digit in a number has a place value based on its position. For example, in 123: 1 is in the hundreds place (1 × 100 = 100) 2 is in the ...

Read More

Sorting elements of stack using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 375 Views

We are required to write a JavaScript function that takes in an array of integers and sorts it using recursion with stack operations (push and pop methods). The function sorts the array in-place without using built-in sorting methods. How It Works The algorithm uses two recursive functions: sortStack() - Removes elements from the stack and recursively sorts the remaining elements sortedInsert() - Inserts an element in its correct position in an already sorted stack Example Here's the complete implementation: const stack = [-3, 14, 18, -5, 30]; const sortStack = (stack ...

Read More

Digit sum upto a number of digits of a number in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 558 Views

We are required to write a JavaScript function that takes in two numbers, let's say m and n as arguments. n will always be smaller than or equal to the number of digits present in m. The function should calculate and return the sum of first n digits of m. Problem Statement If the input numbers are: const m = 5465767; const n = 4; Then the output should be: 20 because 5 + 4 + 6 + 5 = 20 Solution Using String Conversion The most ...

Read More

How to display a message when a given number is in the range using JavaScript?

Prince Varshney
Prince Varshney
Updated on 15-Mar-2026 959 Views

In this article, we will check whether a number lies between a range or not and display a message according to the output we get. This feature of JavaScript allows you to put a number validation while creating a form or any other document. Syntax Following is the syntax to check if number is in range and display the message − if (isNaN(number) || number < lower || number > upper) { document.getElementById("output").innerHTML = number + " is not in range"; } else { document.getElementById("output").innerHTML = number + " is ...

Read More

How to align text content into center using JavaScript?

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

We can align text content into the center using JavaScript by manipulating the CSS properties of HTML elements. This is done by selecting the target element and setting the "text-align" CSS property to "center" using JavaScript's style object. Methods to Center Text There are multiple approaches to center text content using JavaScript: Setting the textAlign property to "center" via JavaScript's style object Using margin properties with auto values for horizontal centering Dynamically creating centered elements with predefined styles Method 1: Using textAlign Property The ...

Read More

How to solve JavaScript heap out of memory on prime number?

Rushi Javiya
Rushi Javiya
Updated on 15-Mar-2026 367 Views

The 'heap out of memory' error occurs when JavaScript code exceeds the allocated memory limit. This commonly happens with inefficient algorithms that have high time or space complexity, especially when processing large numbers. When finding prime factors of very large numbers, naive algorithms can quickly exhaust available memory. The key is optimizing the algorithm to reduce both time and space complexity. The Problem: Inefficient Prime Factor Algorithm The following example demonstrates how a poorly optimized algorithm causes memory issues when processing large numbers: Visualizing Memory Error with Large Numbers ...

Read More

Prime numbers within a range in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 783 Views

We are required to write a JavaScript function that takes in two numbers, say, a and b and returns the total number of prime numbers between a and b (including a and b, if they are prime). For example: If a = 21, and b = 38. The prime numbers between them are 23, 29, 31, 37 And their count is 4 Our function should return 4 Understanding Prime Numbers A prime number is a natural number greater than 1 that has ...

Read More
Showing 16411–16420 of 61,298 articles
Advertisements