Array Methods
let arr = [1, 2, 3, 4, 5];
arr.map(x => x * 2); // [2,4,6,8,10]
arr.filter(x => x > 2); // [3,4,5]
arr.reduce((a,b) => a+b); // 15
arr.find(x => x > 3); // 4
arr.includes(3); // true
Objects
let person = {
name: "Alice",
greet() { return `Hi, I am ${this.name}`; }
};
let {name, greet} = person; // destructuring
let copy = {...person, age: 25}; // spread
Summary
- map, filter, reduce are essential array methods
- Spread operator copies/extends objects
YouTip