uni——遍历循环替换值

案例展示

const fraction_json = ref([]) //星级数组

最终我们需要的格式是:
[{“num”: “5”, “evaluate_id”: “2”}, {“num”: “5”, “evaluate_id”: “3”}]
在这里插入图片描述
参考的方法:

.map() 】方法
map() 方法返回一个新数组,数组中的元素为原始数组元素调用函数处理后的值。
map() 方法按照原始数组元素顺序依次处理元素。

let arr = [1, 2, 3];
let arr1 = arr.map(item => ({
    
    
	id: item
}))
console.log(arr1) //[id:1,id:2,id:3]

猜你喜欢

转载自blog.csdn.net/xulihua_75/article/details/132364503