Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[20210817] (JS) splice() #198

Open
JuHyun419 opened this issue Aug 17, 2021 · 0 comments
Open

[20210817] (JS) splice() #198

JuHyun419 opened this issue Aug 17, 2021 · 0 comments

Comments

@JuHyun419
Copy link
Owner

array.splice(): 자바스크립트 배열 추가, 삭제 함수

  • array.splice(start, count, value1, value2, ...)
let arr = [0, 1, 2, 3];

// 배열의 2번째 위치에 2 추가
arr.splice(2, 0, 2); 
[0, 1, 2, 2, 3]


// 배열 2번째 위치에 1, 2 추가
arr.splice(2, 0, 1, 2); 
[0, 1, 1, 2, 2, 3]


// 배열 1번째 위치부터 1개 원소 제거
arr.splice(1, 1); 
[0, 2, 3]


// 배열 1번째 위치부터 2개 원소 제거
arr.splice(1, 2); 
[0, 3]


// 배열 1번째 위치부터 1개를 제거하고 3를 추가
arr.splice(1, 1, 3); 
[0, 3, 2, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant