1 回答
TA贡献1815条经验 获得超13个赞
我希望这对你有帮助。
var myArray = [ [ 'Procare Fitted Hospital Bed Bottom Sheet, Ivory',
'DT4098',
'Demo',
null,
12300,
2],
[ 'Essential Medical Supply Deluxe Complete Hospital Bed Set',
'ERT665',
'Demo',
null,
11790,
2],
[ 'Dr. Morepen St 04 Acoustic Stethoscope',
'DT4098',
'Demo',
null,
21237,
2],
[ 'CosmoCare KLife 5 Para Patient Monitor',
'YTT690',
'Demo',
null,
11000,
2],
[ 'CosmoCare KLife 5 Para Patient Monitor',
'YTT690',
'Demo',
null,
11000,
2],
[ 'CosmoCare KLife 5 Para Patient Monitor',
'YTT690',
'Demo',
null,
11000,
2],
[ 'CosmoCare KLife 5 Para Patient Monitor',
'YTT690',
'Demo',
null,
11000,
2],
[ 'Dr. Morepen St 04 Acoustic Stethoscope',
'DT4098',
'Demo',
null,
21237,
2],
[ 'Essential Medical Supply Deluxe Complete Hospital Bed Set',
'ERT665',
'Demo',
null,
11790,
2],
[ 'Essential Medical Supply Deluxe Complete Hospital Bed Set',
'ERT665',
'Demo',
null,
11790,
2] ];
let duplicates = [];
let output = myArray.reduce((t, i) => {
if(duplicates.includes(i[1])) {
let myArray = t.filter((item) => item[1] == i[1])[0];
myArray[5] += i[5];
t = t.filter((item) => item[1] != i[1]);
i = myArray;
} else {
duplicates.push(i[1]);
}
t.push(i);
return t;
}, []);
console.log(output);
添加回答
举报
