我试图通过“##”定界符拆分这个字符串。
var historycookie = "8.4707417,77.0463719:Sector 14:Gurgaon##28.3952729,77.3238274:Sector 15:Faridabad";
var history = historycookie.split("##");
alert(history.length);alert(history[0])
history.length
警报给我的结果是 6。
但理想情况下它应该是 2。
history[0]
警报未定义。请帮助我解决这个问题,因为我不明白为什么会这样。
最佳答案
“历史”(甚至“历史”)是由浏览器定义并代表您的历史。
history.length; // is returning size of entries in your history
history[0]; // undefined, because it is not an array
只需更改历史变量的名称即可。
关于javascript - Js 拆分函数给出错误的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37817870/