본문 바로가기

프로그램 강좌

[javascript]배열에서 제거 splice

배열 내에 특정 성분을 제거할때 splice 를 쓰면 된다.

배열.splice(N번째위치0부터, N개);

예제

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let arr = [1, 2, 3, 4, 5, 6];

        arr.splice(0, 2); // 0번째 배열부터 2개, 즉 1, 2 제거
        console.log(arr);
    </script>
</body>

</html>
728x90

'프로그램 강좌' 카테고리의 다른 글

[javascript]문자 치환, replace  (0) 2021.02.23
[javascript]reduce 배열 합계, 다양한 수식 계산  (0) 2021.02.22
[Bulma]버튼  (0) 2020.12.13
[Bulma]Hello World  (0) 2020.12.12
[Bulma]벌마 CSS 프레임워크  (0) 2020.12.11