对象数组里的元素组成二位数组

后端返回的数据为String类型areaList=" [{'county'='Asia', 'city'='Beijing,Hanzhou'},{'county'='Europe', 'city'='London,Paris,Marseille,Lyo'}]"

想将此字符串类型转变为二位数组
[['Asia','Beijing'],['Asia','Hanzhou'], ['Europe', 'London'],['Europe', 'Paris' ],['Europe', 'Marseille'],
['Europe', 'Lyon']]

阅读 982
1 个回答
[...areaList.matchAll(/'county'='(.+?)',\s*'city'='(.+?)'/g)].flatMap(
    ([, county, city]) => city.split(",").map(city => [county, city]),
);
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题