original array, array is not fixed, there may be multiple, id and name are different, sid can be the same (the same belongs to the same category)
var arr = [
{ "id": "1", "sid": "mm", "name": "" },
{ "id": "2", "sid": "mm", "name": "" },
{ "id": "3", "sid": "xx", "name": "64G" },
{ "id": "4", "sid": "xx", "name": "128G" },
{ "id": "5", "sid": "yy", "name": "normal" },
{ "id": "6", "sid": "yy", "name": "plus" }
]
result composition
var arr2 = [
{ name: ",64G,normal", attrs: [{ "id": "1", "sid": "mm", "name": "" }, { "id": "3", "sid": "xx", "name": "64G" }, { "id": "5", "sid": "yy", "name": "normal" }] },
{ name: ",64G,plus", attrs: [{ "id": "1", "sid": "mm", "name": "" }, { "id": "3", "sid": "xx", "name": "64G" }, { "id": "6", "sid": "yy", "name": "plus" }] },
{ name: ",128G,normal", attrs: [{ "id": "1", "sid": "mm", "name": "" }, { "id": "4", "sid": "xx", "name": "128G" }, { "id": "5", "sid": "yy", "name": "normal" }] },
{ name: ",128G,plus", attrs: [{ "id": "1", "sid": "mm", "name": "" }, { "id": "4", "sid": "xx", "name": "128G" }, { "id": "6", "sid": "yy", "name": "plus" }] },
{ name: ",64G,normal", attrs: [{ "id": "2", "sid": "mm", "name": "" }, { "id": "3", "sid": "xx", "name": "64G" }, { "id": "5", "sid": "yy", "name": "normal" }] },
{ name: ",64G,plus", attrs: [{ "id": "2", "sid": "mm", "name": "" }, { "id": "3", "sid": "xx", "name": "64G" }, { "id": "6", "sid": "yy", "name": "plus" }] },
{ name: ",128G,normal", attrs: [{ "id": "2", "sid": "mm", "name": "" }, { "id": "4", "sid": "xx", "name": "128G" }, { "id": "5", "sid": "yy", "name": "normal" }] },
{ name: ",128G,plus", attrs: [{ "id": "2", "sid": "mm", "name": "" }, { "id": "4", "sid": "xx", "name": "128G" }, { "id": "6", "sid": "yy", "name": "plus" }] },
]
if
var arr = [
{ "id": "1", "sid": "mm", "name": "" },
{ "id": "2", "sid": "mm", "name": "" },
{ "id": "3", "sid": "xx", "name": "64G" },
{ "id": "4", "sid": "xx", "name": "128G" }
]
var arr2 = [
{ name: ",64G", attrs: [{ "id": "1", "sid": "mm", "name": "" }, { "id": "3", "sid": "xx", "name": "64G" }] },
{ name: ",128G", attrs: [{ "id": "1", "sid": "mm", "name": "" }, { "id": "4", "sid": "xx", "name": "128G" }] },
{ name: ",64G", attrs: [{ "id": "2", "sid": "mm", "name": "" }, { "id": "3", "sid": "xx", "name": "64G" }] },
{ name: ",128G", attrs: [{ "id": "2", "sid": "mm", "name": "" }, { "id": "4", "sid": "xx", "name": "128G" }] },
]