1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JavaScript  学習記録 (配列 オブジェクト)

Last updated at Posted at 2019-02-15

配列

書き方
[]を使う

const score = [80,90,50];
 console.log(score); // [80,90,50]と出力される
 console.log(score[0]); //80 と出力される
 console.log(score.length); // 3と出力される

 score[2]= 160;
 console.log(score);  // [80,90,160]と出力される

オブジェクト

書き方
{}を使う

スクリーンショット 2019-02-15 1.09.02.png
const player = {
  name: 'Taguchi',
  score: 32,
};

console.log(player); //{name; “Taguchi” , score: 32}と出力される

* playerの名前だけを呼び出す方法

// console.log(player.name);  //書き方は2種類。両方ともnameが呼び出される
// console.log(player['name']); // Taguchi

* 値を変更する場合の書き方

player.score = 100;
console.log(player.score); // 100と出力される

* オブジェクトの要素を後から付け加える

player.email = '***@gmail.com';
console.log(player); // 出力{name: "Taguchi", score: 32, email: "***@gmail.com"}

*オブジェクトの要素を削除

delete player.score;
console.log(player); //scoreが削除されている
1
2
1

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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?