[JAVASCRIPT] 배열 내장 함수 concat, es6 스프레드 연산자
concat배열과 배열을 합쳐 새로운 배열을 만드는 함수. 기존의 배열을 수정되지 않는다. const arr1 = [1, 2, 3];const arr2 = [4, 5, 6]; const concated = arr1.concat(arr2);console.log(arr1);console.log(arr2);console.log(concated);=> [1, 2, 3]=> [4, 5, 6]=> [1, 2, 3, 4, 5, 6] ES6의 스프레드 연산자를 사용해도 같은 결과를 얻을 수 있다. const concated = [...arr1, ...arr2];console.log(arr1);console.log(arr2);console.log(concated);=> [1, 2, 3]=> [4, 5, 6]=> [1, ..
더보기
[JAVASCRIPT] 배열 내장 함수 map, indexOf, findIndex, find, filter
mapmap 함수는 배열을가지고 일련의 과정을 거친 새로운 배열을 만들고 싶을 때 사용하는 함수이다.위의 배열의 제곱근을 가진 배열을 만들고 싶다면 아래처럼 하면 된다. const array = [1, 2, 3]; const square = n => n * n;const squared = array.map(square);console.log(squared);=>[1, 4, 9] 더 간단하게 화살표 함수 문법의 익명 함수를 사용해도 된다. const squared = array.map(n => n * n;);console.log(squared);=>[1, 4, 9] 심화예제 const items = [{id: 1,text: "hello"},{id: 2,text: "bye"}]; const texts = i..
더보기