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 1 year has passed since last update.

入れ子構造からなるjson形式のオブジェクトの複数配列から、特定の値を抽出して、新しいjson形式を作成する。

Posted at

Json形式のデータ 整形方法を学ぶ①

以下のようなデータがあります。

const jJSON= {
  "users": [
    {
      "name": "John",
      "age": 30
    },
    {
      "name": "Jane",
      "age": 25
    }
  ]
}

json形式のオブジェクトから特定の値を抽出するために、JavaScriptのmap()メソッドや、filter()メソッドを使用することができます。これらのメソッドは、配列から新しい配列を作成することができます。

例えば、次のようなコードでは、json形式のオブジェクトから、nameとageの値を抽出し、新しい配列を作成しています。

const extracted = json.users.map(user => ({
  name: user.name,
  age: user.age
}));

console.log(extracted);
// => [
//   {
//     "name": "John",
//     "age": 30
//   },
//   {
//     "name": "Jane",
//     "age": 25
//   }
// ]

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?