Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Js split function giving wrong result

Tags:

javascript

I was trying to split this string through "##" delimitter.

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])

The history.length alert is giving me result as 6. But ideally it should be 2. The history[0] alert is giving undefined. Please help me with this as I am not able to get why this is happening.

like image 747
Uday Khatry Avatar asked Aug 25 '26 12:08

Uday Khatry


1 Answers

"History" (or even "history") is a defined by the browser and representing your history.

history.length; // is returning size of entries in your history
history[0]; // undefined, because it is not an array

Just change the name of the history variable.

like image 123
Eytibi Avatar answered Aug 27 '26 01:08

Eytibi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!