AmitDiwan has Published 10740 Articles

Get the max n values from an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 10:59:48

580 Views

We are required to write a JavaScript function that takes in an array of Numbers as the first argument and a number, say n, as the second argument.Our function should then pick the n greatest numbers from the array and return a new array consisting of those numbers.ExampleThe code for ... Read More

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

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 10:58:28

858 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.ExampleThe code for this will be ... Read More

Combine array of objects in JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 10:58:11

374 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', ... Read More

Filter JavaScript array of objects with another array

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 10:50:49

609 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 ... Read More

Remove the duplicate value from array with images data in JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 10:49:21

469 Views

Suppose, we have some data regarding some images in an array like this −const arr = [{    'image': "jv2bcutaxrms4i_img.png",    'gallery_image': true }, {    'image': "abs.png",    'gallery_image': true }, {    'image': "acd.png",    'gallery_image': false }, {    'image': "jv2bcutaxrms4i_img.png",    'gallery_image': true }, {   ... Read More

Grouping nested array in JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 10:47:13

833 Views

Suppose, we have an array of values like this −const arr = [    {       value1:[1, 2],       value2:[{type:'A'}, {type:'B'}]    },    {       value1:[3, 5],       value2:[{type:'B'}, {type:'B'}]    } ];We are required to write a JavaScript function that ... Read More

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

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 10:43:43

510 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 ... Read More

Combining two arrays in JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 10:42:21

268 Views

We are required to write a JavaScript function that takes in two arrays of the same length.Our function should then combine corresponding elements of the arrays, to form the corresponding subarray of the output array, and then finally return the output array.If the two arrays are −const arr1 = ['a', ... Read More

Remove item from a nested array by indices in JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 10:41:00

1K+ Views

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

Join in nested array in JavaScript

AmitDiwan

AmitDiwan

Updated on 23-Nov-2020 10:35:41

517 Views

Suppose, we have a nested array like this −const arr = ['zero', ['one', 'two' , 'three', ['four', ['five', 'six', ['seven']]]]];We are required to write a JavaScript function that takes in a nested array. Our function should then return a string that contains all the array elements joined by a semicolon ... Read More

Advertisements