Javascript:将动态对象的值合并到另一个对象的数组中

时间:2017-11-17 00:04:35

标签: javascript reactjs react-redux

在React / Redux中,我有一个动态对象(action.payload):

{
  cars: "Ferrari"
}

我需要将它组合到一个嵌套对象(redux):

{
  filters: {
    ships: ['Star'],
    cars: ['Ford']
    airplanes: ['Boeing']
  }
}

我尝试了这个,但似乎这与过滤器'合并了仍在维护:

return {
  ...state,
  filters: Object.assign({}, state.filters, action.payload)
}

我期待数组合并并得到类似的东西:

{
  filters: {
    ships: ['Star'],
    cars: ['Ford', 'Ferrari']
    airplanes: ['Boeing']
  }
}

1 个答案:

答案 0 :(得分:0)

你可以试试这个:

Posts:
    -Kier498dma39md:
        content: 'This is an example post. The numbers above me are an example of the random key I am trying to get.'