Array methods
map, filter, find, sort, slice, reduce, and more — 10 exercises
Exercise 1 / 10
0 solved
Exercise 1/ 10
.map((x) => …)
RuleTakes items one at a time and makes a "new array" of reshaped items. The number of items stays the same
Data(items)
const items = [ { id: 1, name: "Earphones", price: 3000, stock: 5 }, { id: 2, name: "Bottle", price: 800, stock: 0 }, { id: 3, name: "Backpack", price: 5000, stock: 2 }, { id: 4, name: "Notebook", price: 300, stock: 10 }, ]
Example
// An array of each price × 2 items.map((item) => item.price * 2)
→ [6000, 1600, 10000, 600]
The stock of each item after 10 more of each arrive
In plain words:Look at each item one at a time and make a new array where each item is turned into its stock plus 10
Expected result
[15, 10, 12, 20]JavaScript
Solve it to continue