0

In my store I have an array of objects, which in my frontend I need each object to begin with an attribute 'table_id', with an inital value of 1. I tried to do this as seen below, but it just outputs a list of 1's and no updated object.

What is the best way to achieve this?

original array of objects:

var source = [{id: 193, category: "Foo"},
{id: 129, category: "Bar"},
{id: 422, category:  "Foo2"}]

desired array of objects:

var updated_source = [{id: 193, category: "Foo", table_id: 1},
    {id: 129, category: "Bar", table_id: 1},
    {id: 422, category:  "Foo2", table_id: 1}]

What I have tried:

var updated_source = source.map((s) => s.table_id = 1);

Output:

   [1,1,1]
seanberlin
  • 161
  • 1
  • 8

0 Answers0