我想在 javascript 中重新排列一组对象,如下所示:
[{ year: "1950-12-20", product: ["product 1", "product 2, "product 3"] }, { year: "1951-12-20", product: ["product 3", "product 2"] }, { year: "1952-12-20", product: ["product 3", "product 4"] }]
这样我就得到了两个数组,一个是产品,一个是它们出现的年份。
a = ["product 1", "product 2", "product 3", "product 4"]
b = ["1950-12-20", [ "1950-12-20, "1951-12-20"],["1950-12-20", "1951-12-20", "1952-12-20"],"1952-12-20"]
我试图通过嵌套的 for 循环遍历每个对象,但是如何以一种好的方式处理对象数组中的字符串数组?