const arr1 = [1, 2, 3];
const arr2 = [];
for (let i = 0; i < arr1.length; i++) {
arr2.push(arr1[i] * 2);
}
console.log(arr2); // Output: [2, 4, 6]
const arr1 = [1, 2, 3];
const arr2 = arr1.map((v) => v * 2);
console.log(arr2); // Output: [2, 4, 6]
const persons = [
{ name: 'Kim', age: 20 },
{ name: 'Lee', age: 10 },
];
const fullAge = [];
for (let i = 0; i < persons.length; i++) {
if (persons[i].age >= 18) {
fullAge.push(persons[i]);
}
}
console.log(fullAge); // Output: [ { name: 'Kim', age: 20 } ]
const persons = [
{ name: 'Kim', age: 20 },
{ name: 'Lee', age: 10 },
];
const fullAge = persons.filter((person) => person.age >= 18);
console.log(fullAge); // Output: [ { name: 'Kim', age: 20 } ]
const arr = [3, 1, 2];
let sum = 0;
for (let i = 0; i < arr.length; i++) {
sum = sum + arr[i];
}
console.log(sum); // Output: 6
const arr = [3, 1, 2];
const sum = arr.reduce((acc, cur) => acc + cur);
console.log(sum); // Output: 6