筛选出最低价格对象
var arr = [
{
"skuName": "[赠鼠标垫/电池]HP/惠普S1000 plus无线鼠标台式电脑办公笔记本家用商务便携小巧无线鼠标黑灰色鼠标",
"picUrl": "https://imgservice.suning.cn/uimg1/b2c/image/SzK-RKrTs9Ny2YBxHPYBsA.jpg_800w_800h_4e",
"platformName": "苏宁易购",
"price": "39.90",
},
{
"skuName": "[赠鼠标垫/电池]HP/惠普S1000 plus无线鼠标台式电脑办公笔记本家用商务便携小巧无线鼠标黑灰色鼠标",
"picUrl": "https://imgservice.suning.cn/uimg1/b2c/image/SzK-RKrTs9Ny2YBxHPYBsA.jpg_800w_800h_4e",
"platformName": "苏宁易购",
"price": "20",
}]
var minPriceObj = arr.reduce(function (acc, cur) {
// 如果累加器是undefined,或者当前对象的价格更低,则更新累加器
if (!acc || cur.price < acc.price) {
return cur;
}
// 否则返回累加器(保持原样)
return acc;}, undefined); // 初始累加器为undefined
数组对象筛选出最小值
//生成价格数组
var newPriceScreenArr = minPriceObj.map(function (obj) {
return obj.price
})
var minNumber
if (newPriceScreenArr.length > 0) {
minNumber = Math.min(...newPriceScreenArr);
console.log(minNumber,"minNumber")
element.attr('comparePrice', minNumber)
}