3 回答

TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超3個(gè)贊
您可以通過(guò)獲取值的索引來(lái)映射對(duì)象。
const
sample = [{ key:"key1", title: "title1", value: "value1" }, { key:"key2", title: "title2", value: "value2" }, { key:"key3", title: "title3", value: "value3" }],
result = sample.map((o, i) => ({ ...o, title: o.title + (i + 1) }));
console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超4個(gè)贊
希望這會(huì)有所幫助:) 根據(jù)需要在地圖中轉(zhuǎn)換值!:)
const sample = [
{
key:"key1",
title: "title1 + 1",
value: "value1"
},
{
key:"key2",
title: "title2 + 2",
value: "value2"
},
{
key:"key3",
title: "title3 + 3",
value: "value3"
}
];
const other = sample.map(val => ({...val, title: val.title + 'anything'}));
console.log(other);

TA貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超13個(gè)贊
const sample = [
{
key:"key1",
title: "title1",
value: "value1"
},
{
key:"key2",
title: "title2",
value: "value2"
},
{
key:"key3",
title: "title3",
value: "value3"
}]
let result = sample.map((x, i) => {
x.title = x.title + ' + ' + (i + 1);
return x;
});
console.log(result);
添加回答
舉報(bào)