2 回答
TA贡献1796条经验 获得超7个赞
您可以使用 map()
const arr = [{number: "1", type: "date", placeholder: "Semana", validations: Array(1), value: "value"},
{number: "2", type: "text", placeholder: "Marca", validations: Array(3), value: "value"}]
const obj = {
0: "23",
1: "34",
2: "sdfds"
}
const res = arr.map((x,i) => ({...x,value:obj[i]}))
console.log(res)
TA贡献1829条经验 获得超7个赞
您可以使用 forEach 并在每次迭代中访问实际索引以分配正确的值:
data = [
{number: "1", type: "date", placeholder: "Semana", validations: Array(1), value: "value"},
{number: "2", type: "text", placeholder: "Marca", validations: Array(3), value: "value"}
]
values = ["23", "34"]
// Here you do the magic :)
data.forEach((row, index) => row.value = values[index])
添加回答
举报