Open In App

How to handle multiple numeric datasets for calculation using JavaScript ?

Let’s we have given a dataset consists of multiple numeric values, the task is to use that dataset for some calculations. So, we will be creating dictionary like data structure using array of objects. We will discuss how some JavaScript methods can be used to handle this type of data. To handle multiple numeric datasets for calculation we can use JavaScript filter() function and find() function.

Examples: Given a data of Employees.



 id |age |  sal  | exp | com
344 | 45 | 40000 | 12  |  3000
672 | 32 | 30000 | 5   |  8000

We have to follow a few steps to perform a calculation on multiple datasets.

Note: Array of object lets you store multiple values in a single variable. It stores a fixed-size sequential collection of elements of the same type. So, we are using an array of the dictionary-like object here.



Step 1: We will convert this dataset to an array of the object like below:

// Array of the dictionary object
employee = [
    {id: 344, age: 45, sal: 40000, exp: 12, com: 3000},
    {id: 672, age: 32, sal: 30000, exp: 5, com: 8000}
]

Step 2: Now we already have datasets in the form of an array of objects.


Article Tags :