我如何在js中拆分字符串以获取结果:

result = ["post_address", "location", "area"]


这有问题吗?需要有关re的帮助

let re = ???
let arr = "post_address[location][area]".split(re)

最佳答案

只需用/\[|\]/分割,然后删除空字符串。



var output = "post_address[location][area]".split(/\[|\]/).filter((s)=>s.length > 0);

console.log(output);

关于javascript - 我如何在js中拆分数组?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47325866/

10-13 09:35