Sorry if duplicated some issue, but I searched a lot and didn't find anything. I have to fill a table in js. To do this, I take the values of an array of objects (centers) and apply map. Everything works perfectly.
centers = [ { 'center': 'Center 1', 'datos': { "key1":4.67, "key2":3.56 } }, { 'center': 'Center 2', 'datos': { "key1":0.34, "key2":5} }, { 'center': 'Center 3', 'datos': { "key1":3.7, "key2":2.5} } ] let result = centers.map(res => { let columns = {'column1':res.datos.key1, 'column2':res.datos.key2} return columns; }) /* result = [ [ { column1: 4.67, column2: 3.56 }, { column1: 0.34, column2: 5 }, { column1: 3.7, column2: 2.5 } ] ] */ However, the items "key1 ...... key1000" are many and I would like to implement them in the map function like this
var cc = ['key1','key2','key3','key4','key5']; let result = centers.map(res => { let columns = {'column1':res.datos.cc[0], 'column2':res.datos.cc[1], ...........} return columns; }) but it does not take the value of the variable. It's possible with map this?. Thank you.
res.datos[cc[0]]