I have a string build form comma separated values I use split to get each value and after that I want to show each value on a new line but what really happens is that I get each value on a new line except of the last two which are shown together on a same line. Just to make it clear:
value1
,value2
,value3
,value4,value5
Here is the function which I’m using:
_checkDates: function(dates) {
if (dates != null)
{
var zzz = dates.split(',');
var xxx = zzz.length;
console.log(xxx);
for (var i=0; i<=xxx; i++)
{
zzz[i] = zzz[i] + '<br />';
return zzz;
}
}
return dates;
}
Just to be clear this is written in ExtJS 4, I’m almost sure that in this case the problem is pure JavaScript and is not related with ExtJS 4 but anyways, maybe I’m wrong.
So any ideas why does it happen and how I could make that last element to get on a new line as well?
The for-loop is suspicious. Firstly, you do not process all items (the last one is missing, as @sarfraz pointed out). Sencondly you are returning the result (
zzz) in the for-loop body:In Javscript you can simple “join” the array:
Since you are simply replacing strings you could use the
replacemethod: