-
慕森王
您可以通过获取值的索引来映射对象。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; }
-
繁星coding
希望这会有所帮助:) 根据需要在地图中转换值!:)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);
-
慕桂英4014372
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);