簡體   English   中英

我想要一個 function 如果特定值相同則合並子數組

[英]I want a function which merge the sub array if a particular value is same

我有如下二維數組:

[ [ 'Procare Fitted 醫院床底床單,象牙色','DT4098','演示',null,12300,2],[ '基本醫療用品豪華全套醫院床組','ERT665','演示',Z37A6259CC0C1DAE299A78646 11790, 2],['博士。 Morepen ST 04聲學聽覺','dt4098','demo',null,21237,2],['COSMOCMOCARE KLIFE KLIFE KLIFE KLAIFE 5 PARA患者監視器' KLife 5 Para Patient Monitor', 'YTT690', 'Demo', null, 11000, 2], [ 'CosmoCare KLife 5 Para Patient Monitor', 'YTT690', 'Demo', Z37A6259CC0C1DAE299A786648are,9DFFBD], KLife 5 Para Patient Monitor', 'YTT690', 'Demo', null, 11000, 2], ['Dr. Morepen St 04 聲學聽診器', 'DT4098', '演示', null, 21237, 2], ['基本醫療用品豪華全套醫院病床', 'ERT665', '演示', Z37A6259CC0C1DAE29A6259CC0C1DAE29D,9A786179489D, 2 '基本醫療用品豪華全套醫院病床','ERT665','演示',null,11790,2];

我只想根據子數組的第一個索引從多維數組中刪除重復值。 如果第一個索引值相同,則刪除重復的子數組。

[ [ 'Procare Fitted 醫院床底床單,象牙色','DT4098','演示',null,12300,6],[ '基本醫療用品豪華全套醫院病床','ERT665','演示',Z37A6259CC0C1DAE299A78646 11790, 6], ['CosmoCare KLife 5 Para Patient Monitor', 'YTT690', 'Demo', null, 11000, 4]];

我希望這對你有幫助。

 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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM