a = [10, 11, 12, 13, 14, 15];
a.forEach(function (v, i) {
console.log(v, i, this);
});
10 0
11 1
12 2
13 3
14 4
15 5
a = [10, 11, 12, 13, 14, 15];
let answer = a.map(function (v, i) {
return v * v;
});
console.log(answer);
[100, 121, 144, 169, 196, 225]
a = [10, 11, 12, 13, 14, 15];
let answer = a.filter(function (v, i) {
return v % 2 == 0;
});
console.log(answer);
[10, 12, 14]
배열의 합 구할 때 많이 씀
a = [10, 11, 12, 13, 14, 15];
let answer = a.reduce(function (acc, v) {
return acc + v;
}, 0);
console.log(answer);
75