LoginSignup
0

More than 3 years have passed since last update.

配列中のObjectを全て取り出してひとつのObjectにする

Last updated at Posted at 2019-08-01

ついつい忘れてしまうのでメモ
連想配列ひとつずつが配列の要素として存在しているものを、ひとつの連想配列に変換したい。
そんな時はスプレッド演算子を使うと楽です。

const objectsInArray = [
  {
    foo: 'AAA',
  },
  {
    bar: 'BBB',
  },
  {
    baz: 'CCC'
  }
];

const result = Object.assign({}, ...objectsInArray);

console.log(result) // {foo: "AAA", bar: "BBB", baz: "CCC"}

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