-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapping_array.js
More file actions
25 lines (19 loc) · 929 Bytes
/
Copy pathmapping_array.js
File metadata and controls
25 lines (19 loc) · 929 Bytes
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
const products = [
{ name: 'laptop', price: 3200, brand: 'lenovo', color: 'silver' },
{ name: 'phone', price: 7000, brand: 'iphone', color: 'golden' },
{ name: 'watch', price: 3000, brand: 'casio', color: 'yellow' },
{ name: 'sunglass', price: 300, brand: 'ribon', color: 'black' },
{ name: 'camera', price: 9000, brand: 'canon', color: 'gray' }
];
const brands = products.map(product => product.brand);
console.log(brands);
products.forEach(product_1=>console.log(product_1));
products.forEach(product_1=>console.log(product_1.brand));
const cheap=products.filter(product_1=>product_1.price<5000);
console.log(cheap);
const specific=products.filter(p=>p.name.includes('n'));
console.log(specific);
// find
// difference between find and filter is that find directly gives the object , but filter gives the array of the objects
const special=products.find(p=>p.name.includes('n'));
console.log(special);