Javascript:
var string = '(37.961523, -79.40918)';
//remove brackets: replace or regex? + remove whitespaces
array = string.split(',');
var split_1 = array[0];
var split_2 = array[1];
输出:
var split_1 = '37.961523';
var split_2 = '-79.40918';
我应该只使用 string.replace('(', '').replace(')', '').replace(/\s/g, '');
还是 RegEx ?
最佳答案
使用
string.slice(1, -1).split(", ");
关于javascript - 如何使用 JavaScript 拆分此字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6077840/