Array of objects in JavaScript

The most common multidimensional structure is an array of objects. It has some special features. Let's study them. Suppose we have the following array with users:

let users = [ { name: 'name1', surn: 'surn1', }, { name: 'name2', surn: 'surn2', }, { name: 'name3', surn: 'surn3', }, ];

Let's go through all the users and display their names and surnames in the console. When iterating over an array of objects, as a rule, only one loop over the array is used, and inside it, objects are accessed by keys. Let's do it:

for (let user of users) { console.log(user.name + ' ' + user.surn); }

Given the following array of employees:

let employees = [ { name: 'name1', salary: 300, }, { name: 'name2', salary: 400, }, { name: 'name3', salary: 500, }, ];

Display the data for each employee in the format name - salary.

Given the following array of employees:

let employees = [ { name: 'name1', salary: 300, }, { name: 'name2', salary: 400, }, { name: 'name3', salary: 500, }, ];

Display the sum of salaries of all employees.

Given the following array of employees:

let employees = [ { name: 'name1', salary: 300, age: 28, }, { name: 'name2', salary: 400, age: 29, }, { name: 'name3', salary: 500, age: 30, }, { name: 'name4', salary: 600, age: 31, }, { name: 'name5', salary: 700, age: 32, }, ];

Display the sum of the salaries of those employees whose age is equal to or greater than 30 years.

enru