我使用的是角度,我有一些数据:
export class AppComponent {
data = [
{
"area1": {
"format": "changethis"
}
]我想要创建一个方法来改变键的值。例如:
changeKeyValue() {
const key = data[0].area1.format;
const value = 'someOtherValue';
// Code to do the change here
}
}我该怎么做?
发布于 2022-01-05 14:49:40
如果要更新数组中的特定项,可以指定索引data或dataindex并对其进行更新。
data = [
{
"area1": {
"format": "changethis"
}
}
]
let value = "New value"
data[0].area1.format = value;
or
data[0].area1["format"] = value;如果要更新数组中的所有"format“属性,可以使用任何数组方法并遍历它来更新所有值。
例如
data.forEach(item=>item.area1.format = 'new text')https://stackoverflow.com/questions/70594654
复制相似问题