Javascript Articles

Page 258 of 534

JSON group object in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 881 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 353 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 997 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 267 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

Converting string to an array in JavaScript

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 48K+ Views

In JavaScript, converting strings to arrays is a common task when you need to split text into characters or words for processing. JavaScript provides several built-in methods to accomplish this conversion efficiently. This article explores four different methods to convert strings to arrays, each suitable for different use cases and requirements. Using the split() Method The split() method is the most versatile approach for string-to-array conversion. It splits a string into an array of substrings based on a specified separator and returns a new array without modifying the original string. The split() method accepts two optional ...

Read More

How to call a function that returns another function in JavaScript?

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

In JavaScript, calling a function that returns another function involves understanding higher-order functions and closures. When a function returns another function, you can either store the returned function in a variable or call it immediately using double parentheses. Basic Syntax There are two main ways to call a function that returns another function: // Method 1: Store in variable then call let returnedFunction = outerFunction(); returnedFunction(); // Method 2: Call immediately outerFunction()(); Simple Example let outerFunction = function() { ...

Read More

How to stop forEach() method in JavaScript?

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

In JavaScript, programmers can use the forEach() method to iterate through array elements. We can call a callback function, which we pass as a parameter of the forEach() method for every array element. Sometimes, we may need to stop the forEach() loop after executing the callback function for some elements. We can use the 'break' keyword with a normal loop to stop it: for(let i = 0; i < length; i++){ // code if(some condition){ break; } } However, we ...

Read More
Showing 2571–2580 of 5,340 articles
« Prev 1 256 257 258 259 260 534 Next »
Advertisements