LoginSignup
0
0

More than 3 years have passed since last update.

JavaScript勉強の記録その15: 配列にオブジェクトを格納するデータ構造

Posted at

配列とオブジェクトを組み合わせたデータ構造

配列にオブジェクトを格納されてあるようなデータ構造もあります。
以下の例では、pointsという定数に配列が代入してあり、その配列は2つのオブジェクトを持っています。
プロパティーへのアクセスは、 配列名[インデックス番号].キー と記述することで可能になります。

index.js
const points = [
  {x: 100, y: 180},
  {x: 120, y: 160},
];

console.log(points[0]);
//=>{x: 100, y: 180}
console.log(points[0].x);
//=>100
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