有个json数组:
const products=[
{"name": "groupA_01","url": "https://example.com/JXIS14AHZ9MX3"},
{"name": "groupB_01","url": "https://example.com/JXISM5MAE9IXY"},
{"name": "groupC_01","url": "https://example.com/JXISO1ZS24JIT"},
{"name": "groupD_01","url": "https://example.com/JXISO3DMUPLSW"},
{"name": "groupA_02","url": "https://example.com/JXISO7VRRZR56"},
{"name": "groupB_02","url": "https://example.com/JXISOAB64OBOE"},
{"name": "groupC_02","url": "https://example.com/JXISORRSSQGPS"},
{"name": "groupD_02","url": "https://example.com/JXISOWOCC3IZP"},
{"name": "groupA_03","url": "https://example.com/JXISPBQSYV1MQ"},
{"name": "groupB_03","url": "https://example.com/JXISPQ5DJ4HKR"},
{"name": "groupC_03","url": "https://example.com/JXISQ9FR1YKPF"},
{"name": "groupD_03","url": "https://example.com/JXISQ85PZAY9S"},
{"name": "groupA_04","url": "https://example.com/JXISQEO18ECPB"},
{"name": "groupB_04","url": "https://example.com/JXISQJNJ0CRCH"},
{"name": "groupC_04","url": "https://example.com/JXISQZOOS7JE9"},
{"name": "groupD_04","url": "https://example.com/JXISRE6MYUYM9"}
];
我想把它拆分,保存为groupA、groupB、groupC、groupD四个新的json数组,像这样:
const productsGroupA = [
{"name": "groupA_01","url": "https://example.com/JXIS14AHZ9MX3"},
{"name": "groupA_02","url": "https://example.com/JXISO7VRRZR56"},
{"name": "groupA_03","url": "https://example.com/JXISPBQSYV1MQ"},
{"name": "groupA_04","url": "https://example.com/JXISQEO18ECPB"}
];
//其他几个同样。
实际中group有很多,不止ABCD四个,所以不能用groupA、groupB、groupC、groupD作为关键字进行硬编码查询。但是这个规律是存在的,就是name字段=组名+下划线+编号。
问题:
用js实现,应该怎么做呢?