整列
4686 ワード
最初のJavaScriptデータ構造(データの集合)
配列は値の集合です.
配列は値の秩序化された集合です.
シナリオの作成
配列は値の集合です.
配列は値の秩序化された集合です.
シナリオの作成
// To make an empty array
let students = [ ];
// An array of strings
let colors = [‘red’, ‘orange’, ‘yellow’];
// An array of numbers
let lottoNums = [19, 22, 56, 12, 51];
// A mixed array
let stuff = [true, 68, ‘cat’, null];
배열에서 .length의 값은 항상 인덱스의 끝 값보다 1이 크다.
—> colors.length = 3출력 / colors[2] = ‘yellow’
アレイデータアクセス colors[0] ; //‘red’
lottoNums[4]; //‘51’
배열의 인덱스 값을 통해 집합체 안에 들어있는 순서의 숫자로 데이터를 접근할 수 있다.
シナリオの変更 let colors = [‘red’, ‘orange’, ‘yellow’];
colors[0] = ‘apple’;
colors[1] = ‘pineapple’;
colors[2] = ‘lemon’;
colors[5] = ‘melon’;
colors = [‘apple’, ‘pineapple’, ‘lemon’, empty*2, ‘melon’];
colors.length; // 6
colors[4]; // undefined
배열에 값이 다 차 있지는 않지만 6개의 칸이 만들어진 것.
Reference
この問題について(整列), 我々は、より多くの情報をここで見つけました https://velog.io/@99per/배열-99ue5h6kテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol