Related Articles

# How to handle multiple numeric datasets for calculation using JavaScript ?

• Difficulty Level : Easy
• Last Updated : 17 Feb, 2020

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.

• Example 1: Now we will see how we will manipulate or handle the data as per our need. In this example using filter() method (Can calculate multiple values.)
 `  ` `                    `
• Output:
`Total income of Employee with experience of 12years: 43000`
• Example 2: In this example using find() method (Used only to calculate values for unique data like id).
 `                                    `
• Output:
`Total income of the Employee having id:672 = 38000`

My Personal Notes arrow_drop_up