Object Oriented Programming Articles

Page 49 of 589

Retrieve property value selectively from array of objects in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 359 Views

When working with arrays of objects in JavaScript, you often need to extract specific property values based on certain conditions. This tutorial shows how to retrieve property values selectively from an array of objects. Suppose we have an array of objects like this: const arr = [ { id : "23", name : "Item 1", isActive : true}, { id : "25", name : "Item 2", isActive : false}, { id : "26", name : "Item 3", isActive : false}, { id : "30", name ...

Read More

Join in nested array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 536 Views

Joining elements from nested arrays in JavaScript requires flattening the array structure first. This article explores different approaches to join nested array elements with a semicolon separator. The Problem Consider this nested array: const arr = ['zero', ['one', 'two', 'three', ['four', ['five', 'six', ['seven']]]]]; console.log("Original nested array:", arr); Original nested array: [ 'zero', [ 'one', 'two', 'three', [ 'four', [Array] ] ] ] We need to extract all elements and join them with semicolons to get: zero;one;two;three;four;five;six;seven; Using flat() Method (Modern Approach) The flat(Infinity) method flattens ...

Read More

Remove item from a nested array by indices in JavaScript

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

Suppose we have a nested array of objects like this: const arr = [ { value: 'some value' }, { array: [ { value: 'some value' }, { array: [ ...

Read More

Combining two arrays in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 286 Views

In JavaScript, combining two arrays means pairing corresponding elements from each array to create a new array of subarrays. This is commonly known as "zipping" arrays together. For example, if we have two arrays of the same length, we can combine their elements at matching indices to form pairs. If the two arrays are: const arr1 = ['a', 'b', 'c']; const arr2 = [1, 2, 3]; Then the expected output should be: [ ['a', 1], ['b', 2], ['c', 3] ] ...

Read More

JavaScript: create an array of JSON objects from linking two arrays

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 537 Views

Suppose, we have two arrays like these − const meals = ["breakfast", "lunch", "dinner"]; const ingredients = [ ["eggs", "yogurt", "toast"], ["falafel", "mushrooms", "fries"], ["pasta", "cheese"] ]; We are required to write a JavaScript function that takes in two such arrays and maps the subarrays in the second array to the corresponding strings of the first array. Therefore, the output for the above arrays should look like − { "breakfast" : ["eggs", "yogurt", "toast"], ...

Read More

Remove the duplicate value from array with images data in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 500 Views

When working with arrays of objects containing image data, you often need to remove duplicates based on a specific property. Here's how to remove duplicate objects based on the 'image' property value. Sample Data Consider an array of image objects where some images appear multiple times: const arr = [{ 'image': "jv2bcutaxrms4i_img.png", 'gallery_image': true }, { 'image': "abs.png", 'gallery_image': true }, { 'image': "acd.png", 'gallery_image': false }, { ...

Read More

Filter JavaScript array of objects with another array

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 634 Views

Suppose, we have an array of objects like this − const arr = [ {area: 'NY', name: 'Bla', ads: true}, {area: 'DF', name: 'SFS', ads: false}, {area: 'TT', name: 'SDSD', ads: true}, {area: 'SD', name: 'Engine', ads: false}, {area: 'NSK', name: 'Toyota', ads: false}, ]; We are required to write a JavaScript function that takes in one such array as the first argument and an array of string literals as the second argument. Our function should then filter the input ...

Read More

Combine array of objects in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 410 Views

Suppose, we have an array of objects that contains data about some students like this: const arr = [{ name: 'A', idNo: 1, marks: { math: 98, sci: 97, eng: 89 } }, { name: 'B', idNo: 2, marks: { ...

Read More

Remove all occurrences of a multiple occurring element in an array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 885 Views

We are required to write a JavaScript function that takes in an array of literal values. The array might contain some repeating values. Our function should remove all the values from the array that are repeating. We are required to remove all instances of all such elements. Problem Understanding When an element appears multiple times in an array, we want to remove ALL occurrences of that element, not just the duplicates. For example, if 2 appears twice, we remove both instances. Using filter() with indexOf() and lastIndexOf() The most efficient approach uses filter() to keep only ...

Read More

String to binary in JavaScript

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

Converting strings to binary representation is a common task in JavaScript programming. This involves converting each character to its ASCII code and then to binary format. For example, if we have: const str = 'Hello World'; The binary output should be: 1001000 1100101 1101100 1101100 1101111 100000 1010111 1101111 1110010 1101100 1100100 How It Works The conversion process involves three steps: Split the string into individual characters Get the ASCII code of each character using charCodeAt() ...

Read More
Showing 481–490 of 5,881 articles
« Prev 1 47 48 49 50 51 589 Next »
Advertisements