Found 8591 Articles for Front End Technology

Regroup JSON array in JavaScript

AmitDiwan
Updated on 21-Nov-2020 10:31:59

321 Views

Suppose, we have a JSON array of objects like this −const arr = [    {       "id": "03868185",       "month_10": 6,    },    {       "id": "03870584",       "month_6": 2,    },    {       "id": "03870584",       "month_7": 5,    },    {       "id": "51295",       "month_1": 1,    },    {       "id": "51295",       "month_10": 1,    },    {       "id": "55468",       "month_11": 1,    } ];Here, we ... Read More

How to merge two arrays with objects in one in JavaScript?

AmitDiwan
Updated on 21-Nov-2020 10:30:11

1K+ Views

Suppose, we have two arrays of objects like these −const arr1 = [    {name:'test', lastname: 'test', gender:'f'},    {name:'test1', lastname: 'test1', gender:'f'},    {name:'test2', lastname: 'test2', gender:'m'} ]; const arr2 = [    {name:'test21', lastname: 'test21', gender:'f'},    {name:'test1', lastname: 'test1', gender:'f'},    {name:'test2', lastname: 'test2', gender:'m'},    {name:'test22', lastname: 'test22', gender:'m'} ];These arrays do not have any repeating objects within (repeating on the basis of 'name' property) but there exist some objects with repeating names in the first and second objects.We are required to write a JavaScript function that takes two such arrays and returns a new array.The ... Read More

Merge two sorted arrays to form a resultant sorted array in JavaScript

AmitDiwan
Updated on 21-Nov-2020 10:30:47

228 Views

We are required to write a JavaScript function that takes in two sorted array of numbers. The function should merge the two arrays together to form a resultant sorted array and return that array.For example −If the two arrays are −const arr1 = [2, 6, 6, 8, 9]; const arr2 = [1, 4, 5, 7];Then the output array should be −const output = [1, 2, 4, 6, 6, 7, 8, 9];ExampleThe code for this will be −const arr1 = [2, 6, 6, 8, 9]; const arr2 = [1, 4, 5, 7]; const mergeSortedArrays = (arr1 = [], arr2 = []) ... Read More

JavaScript function to prepend string into all the values of array?

Sakshi Jain
Updated on 16-Jan-2025 20:23:16

796 Views

In this article, we will learn to prepend a string into all the values of an array in JavaScript. Arrays are versatile data structures used to store multiple elements of similar or mixed types. A common operation is prepending a string to each element of an array, which involves adding a specified string at the beginning of each element. Problem Statement The problem statement can be deeply visualized as given a string text specifically to prepend or attach at the beginning of each element of the array , the output should return the new resultant array with prepended string value ... Read More

Function to flatten array of multiple nested arrays without recursion in JavaScript

Sakshi Jain
Updated on 21-Aug-2023 16:58:30

630 Views

The problem statement asks the user that given an array of multiple nested arrays the user is asked to flatten the array and convert any more than one dimensional array into one dimensional array in javascript but without using recursion as the major condition to apply for. Also it is one of the most asked front end javascript questions in javascript that is mostly asked for , it is given a deep nested sample array of elements all the problem statement is asking to flatten the deepest nested array into one single collection of elements in one dimension only. ... Read More

Delete elements in first string which are not in second string in JavaScript

Sakshi Jain
Updated on 21-Aug-2023 16:40:01

157 Views

The problem statement asks the user that given two string arrays as an input by the user , we need to delete the elements present in the first string taking in condition which are not present in the second string in javascript. The same problem statement can also be viewed as given two arrays of strings , the solution of the problem statement should return back the newer version of original first string array such that the first string array should only contain the elements that are present in second string array , remembering to preserve the order of ... Read More

Inverting a binary tree in JavaScript

Sakshi Jain
Updated on 22-Aug-2023 18:40:45

799 Views

The problem statement asks the user that given a binary tree , you need to find the mirror image of the elements of the binary tree such that reverse the corresponding and parallel siblings of the tree branches . In short, invert the whole binary tree given the original binary tree as an input. The output of the problem statement looks like a reverse function of the input binary tree as the summary to implement for. What is a Tree in JavaScript A tree refers to one of the optimized data structures to hold data ... Read More

Add all records from one array to each record from a different array in JavaScript

Sakshi Jain
Updated on 22-Aug-2023 18:14:40

504 Views

The problem statement asks the user to add all the records from one array to each record from a different array in JavaScript , the just read statement seems tough to understand and implement code upon . The simplest meaning is given two arrays of different collections of values , we need to generate a combined new array of objects such that the new generated array is a collection of every possible of values present in both arrays for say array1 and array2. The problem statement can be implemented in another way too , saying to find the Cartesian ... Read More

Removing duplicates from a sorted array of literals in JavaScript

Sakshi Jain
Updated on 22-Aug-2023 18:49:22

292 Views

The problem statement says that given a sorted array of numbers as an input source by the user such that we need to remove the duplicates or repeated elements from it making it all new array containing only unique elements inside it. What is a Sorted Array in JavaScript ? A sorted array is a kind of array in javascript that follows a certain order of line in which each element is sorted in alphabetical and numerical order all before using the sort method in javascript itself. The already sorted speed array lets you speed up the ... Read More

Case-sensitive sort in JavaScript

Sakshi Jain
Updated on 22-Aug-2023 18:27:49

2K+ Views

The problem statement says to perform case sensitive sorting in javascript on the array of strings given as an input source by the user . The problem statement wants the developer to perform a case sensitive sorting where all the special characters and numerals should appear first and sort first inplace followed by the sorting of lowercase characters first before the upper case characters . Is JavaScript Case Sensitive ? Before moving forward towards the problem statement we need to understand more about the word “case-sensitive” in the context of JavaScript initially. JavaScript ... Read More

Advertisements