문법
array.map(function(currentValue, index, arr), thisValue)
사용 예시
const numbers = [1, 2, 3, 4, 5];
const dobledNumbers = numbers.map(num => num * 2);
console.log(doubledNumbers); // [2, 4, 6, 8, 10]
const names = ['Anna', 'been', 'seong'];
const people = names.map(name => ({name: name}));
console.log(people);
// [{name: 'Anna', name: 'been', name: 'seong'}]
const fruits = ["apple", "banana", "cherry"];
cost fruitsWithIndex = fruits.map((fruit, index) => ({index, fruit}));
console.log(fruitsWithIndex); // [{index: 0, fruit: "apple"}, {index: 1, fruit: "banana"}, {index: 2, fruit: "cherry"}];
{props.items.map((item) => (
<li key={item}>{item}</li>
))}
문법
array.filter(function(currentValue, index, arr), thisValue)
사용예시
const numbers = [1, 2, 3, 4, 5];
const evenNumbers = numbers.filter(num => num % 2 === 0);
console.log(evenNumbers); // [2, 4] --> 짝수만 필터링 됨
문법
array.reduce(function(accumulator, currentValue, currentIndex, arr), initalValue)
사용예시
const numbers = [1, 2, 3, 4, 5];
const sum = numbers.reduce((acc, cur) => acc + cur, 0);
console.log(sum); // 15
동작 과정
문법
array.forEach(function(currentValue, index, arr), thisValue)사용예시
const fruits = ['apple', 'banana', 'cherry']; fruits.forEach(fruits => console.log(fruit)); // Output: // apple // banana // cherry
문법
array.concat(array2, array3, ... , arrayX)
사용예시
const fruits1 = ['apple', 'banana']; const fruits2 = ['cherry', 'orange']; const allFruits = fruits1.concat(fruits2); console.log(Fruits); // ['apple', 'banana', 'cherry', 'orange']
문법
array.includes(searchElement, fromIndex)
사용예시
const fuits = ['apple', 'banana', 'cherry']; console.log(fruits.includes('banana')); //true console.log(fruits.includes('orange')); //false