首页 > 其他分享 >前端项目实战68-数据处理之一个数组和一个对象

前端项目实战68-数据处理之一个数组和一个对象

时间:2022-10-29 15:38:26浏览次数:53  
标签:index price 数据处理 12312 数组 styleId 68 styleValue styleName

export function myContact(target: any, source: any) {
for (const [key, value] of Object.entries(source)) {
const [name, index] = key.split('-') // 要求key只能有一个'-'字符,前面是price之类的name,后面是index数字
if (name === 'price') { // 可以自定义判断,前缀
target[Number(index)].price = value
}
}
return target
}
//结果值
[
{
"styleName": "我们",
"styleId": 2,
"styleValue": "",
"price": "12312"
},
{
"styleName": "我们",
"styleId": 7,
"styleValue": "",
"price": "12312"
}
] 初始数据值
[
{
"styleName": "我们",
"styleId": 2,
"styleValue": "",
},
{
"styleName": "我们",
"styleId": 7,
"styleValue": "",
}
] 初始数据值
{
"price-0": "12312",
"price-1": "12312",
"price-2": "12312"
}

标签:index,price,数据处理,12312,数组,styleId,68,styleValue,styleName
From: https://blog.51cto.com/u_14476028/5806129

相关文章