LoginSignup
0
0

More than 3 years have passed since last update.

配列

Last updated at Posted at 2021-04-03

配列(要素を取得)

let fruits = ['もも','りんご','バナナ','みかん','ぶどう'];

//1番目の要素
console.log(fruits[0]);  //fruits[0]:もも

//4番目の要素
console.log(fruits[3]); //fruits[3]:みかん

//6番目の要素(空っぽ)
console.log(fruits[6]); //fruits[5]:undefined

indexOf

  • 配列データに存在する場合にその場所を「インデックス番号」で取得
let fruits = ['もも','りんご','バナナ','みかん','ぶどう'];
let fruits2 = fruits.indexOf('りんご');
console.log(fruits2);//1

push

  • 配列要素の追加
let fruits = ['もも','りんご','バナナ','みかん','ぶどう'];
fruits.push ('梨');
console.log(fruits);//(6) ["もも", "りんご", "バナナ", "みかん", "ぶどう", "梨"]

delete

  • 要素の削除
let fruits = ['もも','りんご','バナナ','みかん','ぶどう'];
delete fruits[2];
console.log(fruits);//(5) ["もも", "りんご", empty, "みかん", "ぶどう"]
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0