Web Development Articles

Page 317 of 801

Using BigInt to calculate long factorials in JavaScript

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

In JavaScript, calculating factorials of large numbers requires the BigInt data type to avoid precision loss. BigInt handles arbitrarily large integers, making it perfect for computing long factorials that exceed JavaScript's standard number limits. What is BigInt? BigInt is a built-in JavaScript data type introduced in ECMAScript 2020 that represents integers of arbitrary size. Unlike the standard Number type, which has a maximum safe integer limit of 2^53 - 1, BigInt can handle infinitely large integers. // Regular numbers have limits console.log(Number.MAX_SAFE_INTEGER); // 9007199254740991 // BigInt can handle much larger values console.log(BigInt(Number.MAX_SAFE_INTEGER) * 100n); ...

Read More

Merging subarrays in JavaScript

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

This problem demonstrates how to merge subarrays containing email data by grouping emails under the same person's name. We'll use JavaScript's Set data structure to eliminate duplicates and organize the data efficiently. Understanding the Problem Given an array of subarrays where each subarray contains a person's name followed by their email addresses, we need to merge all emails belonging to the same person into a single subarray. For example, if "Ayaan" appears in multiple subarrays with different emails, we should combine all of Ayaan's emails into one subarray. Algorithm Step 1 − Create a function that ...

Read More

What is the best way to search for an item in a sorted list in JavaScript?

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

When searching for an item in a sorted array in JavaScript, binary search is the most efficient approach. Unlike linear search which checks every element, binary search takes advantage of the sorted order to eliminate half the search space with each comparison. What is Binary Search? Binary search is a divide-and-conquer algorithm that works on sorted arrays. It compares the target value with the middle element and eliminates half of the remaining elements at each step. This approach has O(log n) time complexity, making it much faster than linear search's O(n). How Binary Search Works The ...

Read More

JSON group object in JavaScript

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

In JavaScript, grouping JSON objects means organizing data by common properties or categories. This is useful for data analysis, filtering, and creating structured reports from collections of objects. What is JSON? JSON (JavaScript Object Notation) is a lightweight data format for transferring data between devices. JSON objects use key-value pairs where keys are strings and values can be strings, numbers, booleans, arrays, or nested objects. For example: {"name": "Alice", "age": 25}. const jsonData = [ { team: 'TeamA', score: 20 }, { ...

Read More

Make an array of another array\'s duplicate values in JavaScript

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

In JavaScript, finding duplicate values between two arrays is a common task. This article demonstrates how to create an array containing elements that exist in both arrays using built-in array methods. What is an Array in JavaScript? An array is an object that stores multiple elements in a single variable. Arrays in JavaScript are ordered collections that can hold any data type and provide methods like filter() and indexOf() for manipulation. const array = [201, 202, 405]; Understanding the Logic To find duplicate values between two arrays, we use the filter() method on ...

Read More

Manipulate Object to group based on Array Object List in JavaScript

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

Grouping objects in JavaScript is a common operation when working with arrays of objects. This technique allows you to organize data by specific properties, making it easier to process and analyze related items together. Understanding the Problem Consider an array of objects representing people with properties like name, profession, and age. We want to group these objects by a specific property (like profession) to create an organized structure where each group contains all objects sharing that property value. For example, grouping people by profession would create separate arrays for developers, teachers, engineers, etc. This organization makes it ...

Read More

Manipulating objects in array of objects in JavaScript

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

In JavaScript, manipulating objects within an array of objects is a common task. JavaScript provides several built-in array methods like map(), filter(), find(), and slice() to efficiently handle these operations. What is Object Manipulation in Arrays? Object manipulation in arrays involves three main operations: Updating - Modifying existing object properties Filtering - Selecting objects based on criteria Adding - Creating new objects or properties JavaScript provides methods like map(), filter(), find(), slice(), sort(), reduce(), and others to perform these manipulations efficiently. Original Array ...

Read More

Mapping an array to a new array with default values in JavaScript

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

In JavaScript, mapping an array to a new array with default values is a common task when you need to transform data while ensuring missing or invalid values are replaced with fallback values. What is Array Mapping? Array mapping creates a new array by transforming each element of an existing array through a callback function. The original array remains unchanged, and the new array has the same length. const numbers = [1, 2, 3]; const doubled = numbers.map(x => x * 2); console.log(numbers); // Original unchanged console.log(doubled); // New transformed array ...

Read More

Maximum decreasing adjacent elements in JavaScript

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

In JavaScript, finding the maximum number of decreasing adjacent elements means identifying the longest consecutive sequence where each element is smaller than the previous one. This is essentially finding the longest decreasing subarray. Understanding the Problem We need to find the maximum count of consecutive decreasing pairs in an array. For example, in array [5, 4, 3, 2, 1], we have 4 decreasing pairs: (5, 4), (4, 3), (3, 2), and (2, 1). Finding Decreasing Adjacent Elements 5 arr[0] ...

Read More

How to stop refreshing the page on submit in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 95K+ Views

In this tutorial, we will learn how to prevent forms from refreshing the page when submitted in JavaScript. By default, form submission causes a page refresh, but there are several methods to override this behavior. Using event.preventDefault() to Stop Page Refresh The event.preventDefault() method is the most common and recommended way to prevent the default form submission behavior. Syntax form.addEventListener('submit', function(event) { event.preventDefault(); // Your custom form handling code here }); Example In this example, we create a simple contact form that prevents page ...

Read More
Showing 3161–3170 of 8,010 articles
« Prev 1 315 316 317 318 319 801 Next »
Advertisements