extjs4 - Javascript how to show each element of array on a new line -
i have string build form comma separated values use split
each value , after want show each value on new line happens each value on new line except of last 2 shown on same line. make clear:
value1
,value2
,value3
,value4,value5
here function i'm using:
_checkdates: function(dates) { if (dates != null) { var zzz = dates.split(','); var xxx = zzz.length; console.log(xxx); (var i=0; i<=xxx; i++) { zzz[i] = zzz[i] + '<br />'; return zzz; } } return dates; }
just clear written in extjs 4, i'm sure in case problem pure javascript , not related extjs 4 anyways, maybe i'm wrong.
so ideas why happen , how make last elemnt on new line well?
thanks
leron
the for-loop suspicious. firstly, not process items (the last 1 missing, @sarfraz pointed out). sencondly returning result (zzz
) in for-loop body:
for (var i=0; i<=xxx; i++) { zzz[i] = zzz[i] + '<br />'; return zzz; // for-loop stop here! resulting in ["value1<br />", "value2", etc...] }
in javscript can simple "join" array:
return dates.split(',').join("<br />")
since replacing strings use replace
method:
return dates.replace(",", "<br />");
Comments
Post a Comment