본문 바로가기

Javascript/기초

배열에서 데이터 꺼내기

 

 

배열에 첫 번째로 들어가 있는 데이터를 꺼내고 싶은 경우,

 coworkers[0]이라고 쓰면 첫 번째 자리에 있는 값 = 0번째 자리에 있는 값이 나옵니다.

이를 index 라고 하는데,

index(인덱스) 0번은 "a" 가 되고, 

인덱스 1은 "b" 를 가리킨다고 볼 수 있습니다.

 

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <body>
        <h1>Array</h1>
        <h2>Syntax</h2>
 
        <script>
         
            const boom = ["a", "b"];
 
            document.write(boom[0]); //a
            document.write(boom[1]); //b
        </script>

        <h2>get</h2>
        <script>
           
           
        </script>
    </body>
</html>