상추의 IT저장소
JS) Array.concat() Array.forEach() 본문
Array.concat()
concat 메서드는 인자로 주어진 배열이나 값들을 기존 배열에 합쳐서 새로운 배열을 반환한다.
const array1 = ['a', 'b', 'c'];
const array2 = ['d', 'e', 'f'];
const array3 = array1.concat(array2);
console.log(array3);
>>> 출력값

Array.forEach()
foreach 메서드는 주어진 함수를 배열 요소에 각각에 대해 실행한다.
const arr1 = ['apple', 'kiwi', 'grape', 'orange'];
//forEach로 배열순회
function fun1 (item) {
console.log(item);
}
arr1.forEach(fun1);
// 화살표함수로 구현
arr1.forEach((item) => {
console.log(item);
});
>>> 출력값

참조 : https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
'Javascript' 카테고리의 다른 글
| JS) OS 모듈 (0) | 2022.12.09 |
|---|---|
| JS) 단축평가 (0) | 2022.12.09 |
| JS) Scope (0) | 2022.11.23 |
| JS) 실행컨텍스트 (0) | 2022.11.23 |
| JS) 이벤트 핸들러 (0) | 2022.11.21 |