字符串数组中带有点的字符串(嵌套)到字符串数组

来吧k

我有以下数组:

"country": ["name", "units.size", "units.weight", "formats.date", "formats.number"]

我希望得到以下数组:

"country": ["name", "units", "formats"]

我只想获得没有嵌套属性的对象名称。

君瓦尔

let country = ["name", "units.size", "units.weight", "formats.date", "formats.number"];

country = [...new Set(country.map(a => a.match(/\w+/)[0]))];

console.log(country);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章