AmitDiwan has Published 10744 Articles

Reduce array in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 13:52:56

201 Views

Suppose, we have an array of objects like this −const arr = [    {"time":"18:00:00"},    {"time":"10:00:00"},    {"time":"16:30:00"} ];We are required to write a JavaScript function that takes in one such array and does the following −Extract the times from the json code: so: 18:00:00, 10:00:00, 16:30:00Convert the times ... Read More

How to merge two object arrays of different size by key in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 13:52:02

796 Views

Suppose, we have an object like this −const obj = {    "part1": [{"id": 1, "a": 50}, {"id": 2, "a": 55}, {"id": 4, "a": 100}],    "part2":[{"id": 1, "b": 40}, {"id": 3, "b": 45}, {"id": 4, "b": 110}] };We are required to write a JavaScript function that takes in one ... Read More

How to find inside an array of objects the object that holds the highest value in JavaScript?

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 13:50:31

741 Views

We have an array that holds several objects named student, each object student has several properties, one of which is an array named grades −const arr = [    {       name: "Student 1",       grades: [ 65, 61, 67, 70 ]    },    { ... Read More

How to process JavaScript nested array and display the order of numbers according to the level upto which they are nested?

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 13:48:59

283 Views

Suppose, we have a nested array of numbers like this −const arr = [23, 6, [2, [6, 2, 1, 2], 2], 5, 2];We are required to write a program that should print the numbers (elements) of this array to the screen.The printing order of the numbers should according to the ... Read More

Take in array of objects and convert the above JSON to a Tree-structure in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 13:46:34

1K+ Views

Suppose, we have an array of objects like this −const arr = [    {       "parentIndex": '0' ,       "childIndex": '3' ,       "parent": "ROOT",       "child": "root3"    },    {       "parentIndex": '3' ,       ... Read More

Merge arrays in column wise to another array in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 13:43:15

696 Views

Suppose, we have three arrays of numbers like these −const code = [123, 456, 789]; const year = [2013, 2014, 2015]; const period = [3, 4, 5];We are required to write a JavaScript function that takes in three such arrays. The function should then construct an array of objects based ... Read More

Loop through an index of an array to search for a certain letter in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 13:42:19

1K+ Views

We are required to write a JavaScript function that takes in an array of strings as the first argument and a single character as the second argument.The function should return true if the character specified by second argument exists in any of the strings of the array, false otherwise.ExampleThe code ... Read More

Count by unique key in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 13:40:57

644 Views

Suppose, we have an array of objects like this −const arr = [    {       assigned_user:{          name:'Paul',          id: 34158       },       doc_status: "processed"    },    {       assigned_user:{       ... Read More

Check if user inputted string is in the array in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 13:38:41

479 Views

We are required to write a JavaScript program that provides the user an input to enter a string value.The program should then check the input value against some hard-coded array values. Our program should print true to the screen if the input string value is included in the array, false ... Read More

Reduce an array to groups in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 13:37:04

210 Views

Suppose, we have an array of strings that contains some duplicate entries like this −const arr = ['blue', 'blue', 'green', 'blue', 'yellow', 'yellow', 'green'];We are required to write a JavaScript function that takes in one such array. The function should merge all the duplicate entries with one another.Therefore, the output ... Read More

Advertisements