我有一个像下面这样的对象,它包含一个数组对象,
{
UserId: '634a336122b4b995d25869d5',
CategoryId: '620015b6f61454403daba1b4',
specialUser: [{
"startDate": "2022-10-3",
"endDate": "2022-11-3",
"priceType": 1,
"price": 199
},{
"startDate": "2022-10-3",
"endDate": "2022-11-3",
"priceType": 1,
"price": 199
},{
"startDate": "2022-10-3",
"endDate": "2022-11-3",
"priceType": 1,
"price": 199
}]
}如何从specialUser (包括UserId和CategoryId )中获取值
谢谢你的帮助..。
发布于 2022-10-19 13:10:29
data = {
UserId: '634a336122b4b995d25869d5',
CategoryId: '620015b6f61454403daba1b4',
specialUser: [{
"startDate": "2022-10-3",
"endDate": "2022-11-3",
"priceType": 1,
"price": 199
},{
"startDate": "2022-10-3",
"endDate": "2022-11-3",
"priceType": 1,
"price": 199
},{
"startDate": "2022-10-3",
"endDate": "2022-11-3",
"priceType": 1,
"price": 199
}]
};基本上,您可以使用map并将父属性包含到specialUser数组中。
data.specialUser.map((x)=> {
x.UserId = data.UserId;
x.CategoryId = data.CategoryId;
return x;
});https://stackoverflow.com/questions/74125785
复制相似问题