Array.prototype.unshift()

신승준·2022년 7월 2일
0

Mozilla


Syntax

arr.unshift(element);

push가 배열의 뒤에 요소를 추가한다면, unshift는 배열의 앞에 요소를 추가한다. python의 deque에서 appendleft와 같다.

Example

<button onClick={() => {
    let newTitle = [...title];
    newTitle.unshift(inputValue);
    setTitle(newTitle);
}}>글 등록</button>
profile
메타몽 닮음 :) email: alohajune22@gmail.com

0개의 댓글