0
0

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で連想配列入りの2次元配列を作るサンプル

0
Last updated at Posted at 2019-08-28

やりたいこと

JavaScriptで2次元配列を作って、2次元の内1方向を連想配列にする。

サンプルコード

以下のようにすると、2次元配列の中に連想配列が入るっぽい。

test.html
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>さんぷる</title>
  </head>
  <body>
    <button type="button" id="testButton">てすと</button>
    <script src="test.js"></script>
  </body>
</html>
test.js
let twoDimArray = [];
document.getElementById('testButton').addEventListener('click', function() {
  let infoSet = {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6};
  twoDimArray.push(infoSet);
});

結果

以下のコードで内容を確認したのが下の画像なので、なんとなく上手くいってそう。

test.js
let twoDimArray = [];

document.getElementById('testButton').addEventListener('click', function() {
  let infoSet = {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6};
  twoDimArray.push(infoSet);
  console.log(infoSet);
  console.log(twoDimArray);
  console.log(twoDimArray[0]);
  console.log(twoDimArray[0].a);
});

WS_000026.JPG

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?