Reputation: 7012
I have a method in javascript that use the split method to store the time in an array and then convert the time to seconds. But when I debug, the array always has first 2 elements and ignore the last one. Not sure why?
GetSeconds : function (time) {
var timesecs = 0;
var min = 1;
var timeArray = time.split(ctx.options.separator); //this always contain 2 elements
while (timeArray.length > 0) {
timesecs += min * parseInt(timeArray.pop());
min *= 60;
}
return timesecs;
}
ctx.options.separator
is a variable that stores my delimiter. I was trying with ":" and time passed was "00:00:00". This method is called from another method which increments the second.
I tried it in IE, Chrome and Firebug. This behaves differently when I debug through Visual Studio (as this code is in my .net app)
Upvotes: 0
Views: 232
Reputation: 64
The problem may be a browser issue if ctx.options.separator is being generated properly. Which browser are you using?
Use this cross browser method that will make everything work as expected no matter which browser you use. http://blog.stevenlevithan.com/archives/cross-browser-split
It always has worked for me.
Upvotes: 0
Reputation: 3214
I tried a fiddle and everything works fine there. Are you sure, that ctx.options.separator
works as expected?
Upvotes: 1