AmitDiwan has Published 10744 Articles

How to turn a JSON object into a JavaScript array in JavaScript ?

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 09:59:28

590 Views

Suppose, we have this JSON object where index keys are mapped to some literals −const obj = {    "0": "Rakesh",    "1": "Dinesh",    "2": "Mohit",    "3": "Rajan",    "4": "Ashish" };We are required to write a JavaScript function that takes in one such object and uses the ... Read More

Finding the smallest value in a JSON object in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 09:57:09

842 Views

We are required to write a JavaScript function that takes in a JSON object as one and only argument.The JSON object has string keys mapped to some numbers. Our function should traverse through the object, find and return the smallest value from the object.ExampleThe code for this will be −const ... Read More

Dividing a floating number, rounding it to 2 decimals, and calculating the remainder in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 09:56:06

827 Views

Suppose, we have a floating-point number −2.74If we divide this number by 4, the result is 0.685.We want to divide this number by 4 but the result should be rounded to 2 decimals.Therefore, the result should be −3 times 0.69 and a remainder of 0.67ExampleThe code for this will be ... Read More

How to make Ulam number sequence in JavaScript?

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 09:54:33

132 Views

A mathematician Ulam proposed generating a sequence of numbers from any positive integer n (n>0) as follows −If n is 1, it will stop. if n is even, the next number is n/2. if n is odd, the next number is 3 * n + 1. continue with the process ... Read More

Read by key and parse as JSON in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 09:52:57

252 Views

Suppose, we have a JSON array like this −const arr = [{    "data": [       { "W": 1, "A1": "123" },       { "W": 1, "A1": "456" },       { "W": 2, "A1": "4578" },       { "W": 2, "A1": "2423" ... Read More

Find the smallest sum of all indices of unique number pairs summing to a given number in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 09:50:29

157 Views

We are required to write a function that takes in an array of numbers as the first argument and a target sum as the second argument. We then want to loop through the array and then add each value to each other (except itself + itself).And if the sum of ... Read More

Filtering array of objects in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 09:48:18

801 Views

Suppose, we have two arrays of literals and objects respectively −const source = [1, 2, 3 , 4 , 5]; const cities = [{ city: 4 }, { city: 6 }, { city: 8 }];We are required to write a JavaScript function that takes in these two arrays. Our function ... Read More

Comparing objects in JavaScript and return array of common keys having common values

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 09:47:10

765 Views

We are required to write a JavaScript function that takes in two objects. The function should return an array of all those common keys that have common values across both objects.ExampleThe code for this will be −const obj1 = { a: true, b: false, c: "foo" }; const obj2 = ... Read More

How to convert square bracket object keys into nested object in JavaScript?

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 09:44:23

772 Views

We know that there are two ways we can access nested keys within an Object in JavaScript.For instance, take this object −const obj = {    object: {       foo: {          bar: {             ya: 100       ... Read More

How to iterate an array of objects and build a new one in JavaScript ?

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 09:42:41

114 Views

Suppose, we have an array of objects like this −const arr = [    {       "customer": "Customer 1",       "project": "1"    },    {       "customer": "Customer 2",       "project": "2"    },    {       "customer": "Customer ... Read More

Advertisements