Ota*_*der 1 javascript reactjs
基本上我有一个对象数组。每个对象都有一个数组,我需要更改其值。
我正在使用React,所以这是一个状态:
[
{
"points": [
60,
5,
60,
20,
70,
20,
70,
15
],
"finished": true,
"color": "#6292C6"
},
{
"points": [
80,
15,
80,
25,
90,
25
],
"finished": true,
"color": "#3FD971"
},
{
"cultureName": "",
"points": [],
"finished": false
}
]
Run Code Online (Sandbox Code Playgroud)
更改points此状态的值的最佳方法是什么?我需要将它们乘以一个系数(4.96)。
Dup*_*cas 12
map您的数组,其中的spread每个对象仅覆盖属性points(map将每个项目乘以factor 4.96)
const data = [{id: 1, points: [1,2,3]}, {id: 2, points: []}]
const changedData = data.map(item =>({
...item,
points : item.points.map(value => value * 4.96)
}))
console.log(changedData)Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
98 次 |
| 最近记录: |