Javascript Articles

Page 246 of 534

Sorting numbers according to the digit root JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 285 Views

In this problem statement, our task is to sort numbers according to the digit root and implement this problem with the help of Javascript functionalities. So we can solve this problem with the help of loops in Javascript. What is digit root? The digit root of a given number is basically the sum of its digits. Repeat the calculation until the result is not a single digit. Let's take an example for the digit root, calculate the digit root for 1234, 1 + 2 + 3 + 4 = 10 = 1 + 0 = 1. Similarly the ...

Read More

Sorting odd and even elements separately JavaScript

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

In JavaScript, we can sort odd and even positioned elements separately within an array while maintaining their relative positions. This approach sorts elements at even indices (0, 2, 4...) and odd indices (1, 3, 5...) independently. Understanding the Problem Given an array, we need to sort elements at even indices separately from elements at odd indices. For example, with array [9, 2, 7, 4, 5, 6, 3, 8, 1]: Even indices (0, 2, 4, 6, 8): [9, 7, 5, 3, 1] → sorted: [1, 3, 5, 7, 9] Odd indices (1, 3, 5, 7): [2, 4, ...

Read More

Sorting strings with decimal points in JavaScript

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

In JavaScript, sorting strings with decimal points requires converting them to numbers first, since string comparison would treat "10.0" as less than "2.0". This article demonstrates how to sort decimal string arrays properly. Understanding the Problem When sorting strings containing decimal numbers, JavaScript's default string comparison doesn't work numerically. For example, ['3.3', '4.4', '2.3', '1.2'] should become ['1.2', '2.3', '3.3', '4.4'], but string sorting would give incorrect results. The Solution Approach To solve this problem, we need to: Convert decimal strings to numbers using parseFloat() Sort the numbers numerically Convert back to strings if needed ...

Read More

Special arrays in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 577 Views

In JavaScript, special arrays refer to arrays with unique characteristics or behaviors that differ from regular arrays. The main types include typed arrays for binary data, sparse arrays with missing elements, and arrays with non-numeric properties. Typed Arrays Typed arrays are array-like objects that provide a mechanism for accessing raw binary data. They have a fixed length and store elements of a specific numeric type, making them ideal for working with binary data efficiently. Common Typed Array Types // 8-bit signed integers const int8 = new Int8Array(4); int8[0] = 127; // max value ...

Read More

Spiraling the elements of a square matrix JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 353 Views

In this problem statement, our main aim is to spiral the elements of a square matrix with the help of JavaScript functionalities. We'll traverse the matrix in a clockwise direction, starting from the top-left corner and moving in a spiral pattern. Understanding the Problem The problem is to write a function in JavaScript that converts a 2D matrix into a 1D array by traversing elements in a clockwise spiral pattern. For example, if we have a matrix: [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] ...

Read More

Split a range of number to a specific number of intervals JavaScript

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

In this problem statement, our task is to write a function that splits a range of numbers into a specific number of intervals using JavaScript. We need to provide the start value, end value, and the number of intervals. Understanding the Problem The problem requires creating a function that divides a numerical range into equal intervals. The inputs are the starting number, ending number, and desired number of intervals. The output should be an array of subarrays, where each subarray represents an interval with its start and end values. For example, if the range is from 0 ...

Read More

Using Sieve of Eratosthenes to find primes JavaScript

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

In this article, we'll implement the Sieve of Eratosthenes algorithm in JavaScript to efficiently find all prime numbers up to a given limit. This classical algorithm is much faster than checking each number individually for primality. What is the Sieve of Eratosthenes Algorithm? The Sieve of Eratosthenes is an ancient and efficient algorithm for finding all prime numbers up to a given range. It works by creating a list of all numbers from 2 to the target number, then systematically eliminating the multiples of each prime number, leaving only the primes. Sieve of ...

Read More

Adding Animations on Scroll with HTML, CSS and AOS.js

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

AOS.js (Animation on Scroll) is a lightweight JavaScript library that makes it easy to add scroll-triggered animations to web pages. By simply adding CSS classes and data attributes to HTML elements, you can create engaging visual effects without writing complex JavaScript code. In this tutorial, we will explore different types of animations available in AOS.js, including fade, flip, and zoom effects, along with practical examples. Setting Up AOS.js Before using AOS.js, you need to include the CSS and JavaScript files in your HTML document. Add the following CDN link in the section: ...

Read More

Auto-formatting Input Text Content with Cleave.js

Mukul Latiyan
Mukul Latiyan
Updated on 15-Mar-2026 977 Views

Auto-formatting is one of those features that are hard to implement but at the same time increases the user experience a lot. There are different JavaScript libraries that one can use when they want to auto-format the input text content, but the most popular of them is Cleave.js. Cleave.js is a JavaScript library that is mainly used when we want to format the input text content and it works very smoothly. It is very lightweight and easy to get started with. In this tutorial, we will take a couple of examples to demonstrate how you can use Cleave.js to ...

Read More

Building a Text Editor using Quill.js

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

Quill is a free and open-source WYSIWYG (What You See Is What You Get) text editor built for modern web applications. It offers a highly customizable interface with an expressive API, making it easy to integrate rich text editing capabilities into your projects. In this tutorial, we'll explore how to build text editors using Quill.js through practical examples, from basic setup to advanced customization. Setting Up Quill.js To get started with Quill, include the CSS and JavaScript files in your HTML document's section: The first link provides the CSS styling, ...

Read More
Showing 2451–2460 of 5,340 articles
« Prev 1 244 245 246 247 248 534 Next »
Advertisements