如何创建一个对象数组,其中一个属性是来自单个数组的数组
我得到了这个数组:
[
name1,
[email protected],
[email protected],
[email protected],
name2,
[email protected],
name3,
name4,
[email protected],
[email protected],
[email protected],
[email protected],
[email protected],
]
从那个数组中,我需要对其进行解析并创建一个如下:
[
{ dlName: < element without @ > , members: [<elements with @ >]},
{ dlName: < element without @ > , members: [<elements with @ >]},
{ dlName: < element without @ > , members: [<elements with @ >]}
]
示例:
[
HR,
[email protected],
[email protected],
[email protected],
cyber,
[email protected],
[email protected],
accessibility,
accounting,
[email protected],
[email protected]
]
输出:
[
{ dlName: HR , members: [[email protected],[email protected],[email protected],]},
{ dlName: cyber , members:[[email protected],[email protected],]},
{ dlName: accesibility , members: []},
{ dlName: accounting , members: [[email protected],[email protected]]}
]
如何获得此输出,我尝试过的一切都不适合我。
提前致谢
I got this array:
[
name1,
[email protected],
[email protected],
[email protected],
name2,
[email protected],
name3,
name4,
[email protected],
[email protected],
[email protected],
[email protected],
[email protected],
]
From that array I need to parse it and create an array like the following:
[
{ dlName: < element without @ > , members: [<elements with @ >]},
{ dlName: < element without @ > , members: [<elements with @ >]},
{ dlName: < element without @ > , members: [<elements with @ >]}
]
example:
[
HR,
[email protected],
[email protected],
[email protected],
cyber,
[email protected],
[email protected],
accessibility,
accounting,
[email protected],
[email protected]
]
output:
[
{ dlName: HR , members: [[email protected],[email protected],[email protected],]},
{ dlName: cyber , members:[[email protected],[email protected],]},
{ dlName: accesibility , members: []},
{ dlName: accounting , members: [[email protected],[email protected]]}
]
How can I get this output, everything I tried does not work for me needs.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过查看字符串来减少阵列。
如果您获得了
'@'
将字符串添加到成员
的最后一个对象,则其他sose将新对象添加到结果集中。You could reduce the array by having a look to the strings.
If you got an
'@'
add the string to the last object tomembers
, otherose add a new object to the result set.