-
Notifications
You must be signed in to change notification settings - Fork 0
/
6.arrays_of_objects.js
38 lines (35 loc) · 1.05 KB
/
6.arrays_of_objects.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* An example of iterating through an array of objects.
* Data is often transferred between clients and servers in such a format.
*
*/
// an array of objects, where each object represents a product for sale
const products = [
{
id: 1,
title: 'Boa, emerald green tree',
country: 'Russia',
price: '$31.82',
description: 'Sed ante. Vivamus tortor. Duis mattis egestas metus.'
},
{
id: 2,
title: 'Bleu, blue-breasted cordon',
country: 'Ethiopia',
price: '$35.66',
description: 'Praesent blandit. Nam nulla. Integer pede justo, lacinia eget, tincidunt eget, tempus vel, pede.'
},
{
id: 3,
title: 'Southern elephant seal',
country: 'Kuwait',
price: '$31.06',
description: 'Nullam porttitor lacus at turpis. Donec posuere metus vitae ipsum. Aliquam non mauris.'
}
];
//console.log( products ); // output the raw data
// loop through each product
products.map( (product) => {
// print the title and price of each product
console.log(`${product.title} - ${product.price}`)
});