배열은 여러 개의 데이터를 순서대로 저장하는 목록입니다.
배열은 서로 관련된 데이터를 저장하는 데 유용합니다. 배열은 모든 유형의 데이터를 포함할 수 있습니다. 예를 들어 배열은 문자열로 된 색상 목록을 포함할 수 있습니다. 배열은 다음과 같이 생성됩니다:
let colors = ['deeppink', 'darkorchid', 'magenta'];
배열의 각 데이터는 요소라고 불립니다. 각 요소는 배열 내에서 주소 또는 인덱스를 가집니다. 변수 colors는 세 개의 String 요소인 'deeppink', 'darkorchid', 'magenta'를 가리킵니다. 배열은 0부터 시작하는 인덱스를 가지며, 따라서 'deeppink'는 인덱스 0에, 'darkorchid'는 인덱스 1에, 'magenta'는 인덱스 2에 있습니다. 배열 요소는 다음과 같이 인덱스를 사용하여 액세스할 수 있습니다:
let zeroth = colors[0]; // 'deeppink'
let first = colors[1]; // 'darkorchid'
let second = colors[2]; // 'magenta'
요소는 push() 메서드를 호출하여 배열의 끝에 추가할 수 있습니다.
colors.push('lavender');
<p>let third = colors[3]; // 'lavender'
</p>배열에 대한 자세한 내용은 MDN에서 확인할 수 있습니다.
예제
This page is generated from the comments in src/core/reference.js . Please feel free to edit it and submit a pull request!