Object Oriented Programming Articles

Page 43 of 589

JavaScript - Find keys for the matched values as like query in SQL

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 457 Views

In JavaScript, you can filter object properties based on value matching, similar to SQL's WHERE clause with LIKE operator. This is useful for searching through data structures and finding keys that match specific criteria. Problem Statement Given an object with key-value pairs, we need to find all keys whose values contain a specific search term (case-insensitive). const obj = { "100": "Jaipur", "101": "Delhi", "102": "Raipur", "104": "Goa" }; We want to create a function that returns ...

Read More

List all duplicate values in a nested JavaScript object

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

When working with nested JavaScript objects, you may need to find duplicate values that appear at different levels of nesting. This tutorial shows how to recursively search through a nested object and identify all duplicate values. Problem Statement Consider a nested object containing pet information: const pets = { owner1: 'Frank', owner2: 'Curly', owner3: 'Maurice', dogs: { terriers: { name1: ...

Read More

Search by id and remove object from JSON array in JavaScript

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

Suppose, we have an array of objects that contains data about some movies like this − const arr = [ {id: "1", name: "Snatch", type: "crime"}, {id: "2", name: "Witches of Eastwick", type: "comedy"}, {id: "3", name: "X-Men", type: "action"}, {id: "4", name: "Ordinary People", type: "drama"}, {id: "5", name: "Billy Elliot", type: "drama"}, {id: "6", name: "Toy Story", type: "children"} ]; We are required to write ...

Read More

JavaScript: Sort Object of Objects

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

Suppose we have an Object of Objects like this: const obj = { "CAB": { name: 'CBSSP', position: 2 }, "NSG": { name: 'NNSSP', position: 3 }, "EQU": { name: 'SSP', position: 1 } }; We need to write a JavaScript function that sorts the sub-objects based on the 'position' property in ascending order. Method 1: Using Object.keys() and ...

Read More

Group Similar Items in JSON in JavaScript

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

Suppose, we have a JSON Array that contains data about some tickets like this: const arr = [ { "quantity": "1", "description": "VIP Ticket to Event" }, { "quantity": "1", "description": "VIP Ticket to Event" }, { "quantity": ...

Read More

How to find all partitions of a multiset, where each part has distinct elements in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 276 Views

Finding all partitions of a multiset where each part contains distinct elements is a complex combinatorial problem. We need to create an algorithm that generates all possible ways to divide elements into groups without repetition within each group. Let's say we have an array with repeated elements: const arr = [A, A, B, B, C, C, D, E]; We need to find all combinations that use the entire array, where no elements are repeated within each partition. Example Partitions [A, B, C, D, E] [A, B, C] [A, B, C, D] [A, ...

Read More

Find all occurrences of a word in array in JavaScript

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

When working with arrays in JavaScript, you might need to find how many elements contain a specific word or substring. This article demonstrates multiple approaches to count occurrences of a word within array elements. Problem Statement We need to write a JavaScript function that takes an array of strings as the first argument and a search word as the second argument. The function should return the count of array elements that contain the specified word. Method 1: Using filter() and indexOf() This approach uses filter() to find matching elements and returns the length of the filtered ...

Read More

Sorting array of strings having year and month in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 284 Views

Suppose, we have an array of strings that contains month-year combined strings like this: const arr = ["2009-feb", "2009-jan", "2010-mar", "2010-jan", "2011-jul", "2011-sep", "2011-jan", "2012-jan", "2012-dec", "2012-feb", "2013-may", "2013-jul", "2013-jun", "2014-jan", "2014-dec", "2014-may", "2015-may", "2015-jan", "2015-jun", "2016-jan", "2016-dec"]; We need to write a JavaScript function that takes such an array and sorts these dates from oldest to latest order. Approach The solution involves creating a custom sorting function that: Splits each date string to separate year and month Converts month names to numeric values ...

Read More

Compute cartesian product of elements in an array in JavaScript

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

The Cartesian product of two sets (arrays) A and B, denoted A × B, is the set (array) of all ordered pairs (a, b) where a is in A and b is in B. In simpler terms, a cartesian product of two arrays is a permutation of all possible arrays of two elements whose first element belongs to the first array and the second element belongs to the second array. Example of Cartesian Product If the two arrays are: const arr1 = [1, 2, 3]; const arr2 = [4, 5]; Then their cartesian ...

Read More

Group by JavaScript Array Object

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

Suppose we have an array of arrays that contains the marks of some students in some subjects like this − const arr = [ ["English", 52], ["Hindi", 154], ["Hindi", 241], ["Spanish", 10], ["French", 65], ["German", 98], ["Russian", 10] ]; We are required to write a JavaScript function that takes in one such array and returns an object of objects. The return object should contain an object for each unique subject, and that object should contain information like the number of appearances ...

Read More
Showing 421–430 of 5,881 articles
« Prev 1 41 42 43 44 45 589 Next »
Advertisements