Array.from (객체 복사 및 생성)
developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/from
Array.from() - JavaScript | MDN
Array.from() Array.from() 메서드는 유사 배열 객체(array-like object)나반복 가능한 객체(iterable object)를 얕게 복사해새로운Array 객체를 만듭니다. The source for this interactive example is stored in a GitHub repository. If
developer.mozilla.org
Array.from
은 메서드는 유사 배열 객체(array-like object)
나
반복 가능한 객체(iterable object)
를 얕게 복사해 새로운 Array 객체를 만듭니다.
유사배열 객체는 기본적으로 string
이나 기타 배열객체화 시킬수 있는것 들을 이야기 합니다.
const str = '1234567'; const result = Array.from(str, mapFunction); function mapFunction(x) { return Number(x); } console.log(result); // [1, 2, 3, 4, 5, 6, 7] const numbers = [1,2,3,4,5,6,7,8]; const newNumbers = Array.from(numbers, mapFuntion2); function mapFuntion2(x) { return x * 2; } console.log(newNumbers); // [2, 4, 6, 8, 10, 12, 14, 16] const sampleArray = Array.from({length : 10}, (_, i) => i); console.log(sampleArray); // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
'JavaScript > Vanilla JS' 카테고리의 다른 글
Array.splice() (배열 삭제 및 추가) (0) | 2021.03.26 |
---|---|
Array.some() (배열내에 요소 찾기) (0) | 2021.03.25 |
js random color 생성 (0) | 2021.03.16 |
Array.prototype.forEach() (0) | 2021.03.03 |
정렬하기 array.sort() (0) | 2021.03.02 |
댓글
이 글 공유하기
다른 글
-
Array.splice() (배열 삭제 및 추가)
Array.splice() (배열 삭제 및 추가)
2021.03.26 -
Array.some() (배열내에 요소 찾기)
Array.some() (배열내에 요소 찾기)
2021.03.25 -
js random color 생성
js random color 생성
2021.03.16 -
Array.prototype.forEach()
Array.prototype.forEach()
2021.03.03
댓글을 사용할 수 없습니다.