0
1

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 3 years have passed since last update.

【Javascript】オブジェクトの要素を配列で扱いたい場合

Posted at

###以下のオブジェクトのキーとバリューをそれぞれ1つの配列で扱いたい場合

sample.js
  const point = {
    x: 100,
    y: 200,
  };

###期待する結果
Key : x Value: 100
Key : y Value: 200

##実行コード

sample.js
  const keys = Object.keys(point);
  keys.foreach((key) => {
    console.log("Key: ${key}, Value: ${point[key]}");
  });

1.Object.keysメソッドにオブジェクトpointを渡すことによって 配列[x,y]が生成される
2.配列にはfor文が使えるのでforeachを使うとそれぞれの配列からにキーとバリューを扱うことができる

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?