在JavaScript中分割点或逗号

时间:2019-06-21 20:42:46

标签: javascript split

如何在此代码中写点或逗号:

var mytext = text.split('.');

我想说点(点或逗号),我不知道如何在点和逗号之间写“或”。

1 个答案:

答案 0 :(得分:2)

您可以使用正则表达式查找点或逗号。

var text = 'foo,bar.baz',
    array = text.split(/[.,]/);

console.log(array);