Nikitasha Shrivastava

Nikitasha Shrivastava

163 Articles Published

Articles by Nikitasha Shrivastava

Page 13 of 17

JavaScript Group a JSON Object by Two Properties and Count

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

When working with JSON data, you often need to group objects by multiple properties and count occurrences. This is useful for data analysis, creating summaries, or generating reports from complex datasets. What is JSON? JSON (JavaScript Object Notation) is a lightweight data format for transferring data between systems. It uses key-value pairs where keys are strings and values can be various data types. Each entry is separated by commas, for example: {"name": "Peter", "age": 25}. const jsonData = [ { ...

Read More

isSubset of two arrays in JavaScript

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

In JavaScript, checking if one array is a subset of another means verifying that all elements of the second array exist in the first array. This is a common programming problem that can be solved efficiently using JavaScript's Set data structure. Understanding the Problem An array is considered a subset of another array if all its elements are present in the parent array. For example, [2, 4, 6] is a subset of [1, 2, 3, 4, 5, 6] because all elements (2, 4, 6) exist in the larger array. Using Set for Efficient Lookup The most ...

Read More

Split array entries to form object in JavaScript

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

In JavaScript, converting array entries into objects is a common task. This article explores multiple approaches to split array elements and transform them into key-value pairs or structured objects. Understanding the Problem We need to convert array elements into objects. This can involve splitting string elements into key-value pairs or simply transforming array indices into object keys. Let's explore different methods to achieve this. Using reduce() and split() Methods This method splits array entries by a delimiter and groups them with counts, useful for data aggregation. Example // Define data in the form ...

Read More

Counting duplicates and aggregating array of objects in JavaScript

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

Counting duplicates and aggregating arrays of objects is a common task in JavaScript data processing. This involves identifying duplicate elements and creating new structures that group and count related data. Understanding the Problem The goal is to transform an array of objects by grouping similar items and counting occurrences. For example, if we have users with different skills, we want to group by skill and collect all users for each skill. What is Aggregating Array of Objects? Aggregation combines multiple objects into a summarized structure. Instead of having duplicate entries, we group related data together with ...

Read More

Sort Array of objects by two properties in JavaScript

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

Sorting an array of objects by multiple properties is a common task in JavaScript. This involves first sorting by the primary property, then by the secondary property when the primary values are equal. Understanding the Problem When working with arrays of objects, we often need to sort by multiple criteria. For example, sorting employees by department first, then by salary within each department. JavaScript's Array.sort() method with a custom comparator function makes this possible. The key is to create a comparison function that first checks the primary property, and only compares the secondary property when the primary ...

Read More

Merge and group object properties in JavaScript

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

In JavaScript, merging and grouping object properties is a common task when working with arrays of objects. This technique allows you to combine objects that share a common property (like a name or ID) into single objects with all their properties merged. Understanding the Problem We need to create a JavaScript function that takes an array of objects and groups them by a common property (like 'name'), merging all properties of objects that share the same value for that property. Input: [ {name: 'Adi', age: 22, color:'Black'}, {name: 'Adi', weight: 40, height: ...

Read More

How to sort an array of objects based on the length of a nested array in JavaScript

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

In JavaScript, you can sort an array of objects based on the length of nested arrays using the sort() method with a custom comparison function. This technique is useful when organizing data by array size. Understanding the Problem Consider an array of objects where each object contains a nested array property. To sort by nested array length, we need a comparison function that compares the length property of these nested arrays. Sorting by Nested Array Length Before Sorting ...

Read More

Manipulate Object to group based on Array Object List in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 346 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

Sorting an integer without using string methods and without using arrays in JavaScript

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

In this problem, we need to sort the digits of an integer number without using string methods or arrays in JavaScript. We'll use mathematical operations and loops to extract, compare, and rearrange digits. Understanding the Problem Sorting an integer means arranging its digits in ascending or descending order. For example, if we have the number 784521, the sorted result would be 124578 (ascending) or 875421 (descending). We need to achieve this using only mathematical operations without converting to strings or using arrays. Algorithm Overview Our approach involves two main functions: sortInteger() - Main function ...

Read More

Merging subarrays in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 667 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
Showing 121–130 of 163 articles
« Prev 1 11 12 13 14 15 17 Next »
Advertisements