Web Development Articles

Page 229 of 801

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 292 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 539 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 506 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 640 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 415 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 893 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

Implementing Heap Sort using vanilla JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 301 Views

Heap Sort is a comparison-based sorting algorithm that can be thought of as an improved selection sort. Like selection sort, it divides input into sorted and unsorted regions, but uses a binary heap data structure to efficiently find the maximum (or minimum) element. How Heap Sort Works Heap Sort works in two main phases: Build Max Heap: Convert the array into a max heap where parent nodes are larger than their children Extract Elements: Repeatedly remove the maximum element (root) and restore the heap property Implementation Here's a complete implementation of Heap Sort ...

Read More

Prefix calculator using stack in JavaScript

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

A Reverse Polish Notation (RPN) calculator processes operators after their operands, using a stack data structure. This implementation evaluates mathematical expressions efficiently without parentheses. How RPN Works In RPN, operators follow their operands. For example, "3 4 +" means "3 + 4". The algorithm uses a stack: Push operands onto the stack When encountering an operator, pop two operands, perform the operation, and push the result back The final stack contains the result Step-by-Step Process Consider the input array: const arr = [1, 5, '+', 6, 3, '-', '/', 7, '*']; ...

Read More
Showing 2281–2290 of 8,010 articles
« Prev 1 227 228 229 230 231 801 Next »
Advertisements