Ryu.log

Array.prototype.unshift() 본문

Prev-content

Array.prototype.unshift()

류뚝딱 2018. 11. 13. 16:00

Array.prototype.unshift()

Array.prototype.unshift() 메서드는 새로운 요소를 배열의 맨앞쪽에 추가한 뒤, 합쳐진 배열을 반환한다.

let array1 = [1, 2, 3]; console.log(array1.unshift(4, 5)); // output: 5 console.log(array1); // output: Array [4, 5, 1, 2, 3]

반환값

메서드를 호출한 배열과 추가된 배열값이 합쳐진 배열

예제코드

let arr = [1, 2];

arr.unshift(0); // result of call is 3, the new array length
// arr is [0, 1, 2]

arr.unshift(-2, -1); // = 5
// arr is [-2, -1, 0, 1, 2]

arr.unshift([-3]);
// arr is [[-3], -2, -1, 0, 1, 2]





'Prev-content' 카테고리의 다른 글

[ Webpack ] CRA(create-react-app) Webpack sass-loader 기본 루트 설정  (0) 2019.01.24
Array.prototype.splice()  (0) 2018.11.13
Array.prototype.shift()  (0) 2018.11.13
Array.prototype.pop()  (0) 2018.11.13
Array.prototype.sort()  (0) 2018.11.12
Comments