How do we mutate a string in Javascript -
i have string t2 , want mutate string based on below if
condition . tried .replace
doesnt work.
t2 = "<li class='coded_true'>"+tp_info.elements["info"].cdatas.join.strip+"</li>" if (tp_info.attributes["itcoded"]== "true") t2= t2.replace(t2,"<li class='coded_true itcoded_true'>"+tp_info.elements["info"].cdatas.join.strip+"</li>"); end
thanks!
there's no need use .replace()
substitute entire string:
t2 = t2.replace(t2, ...);
at point, can assign replacement directly:
t2 = "<li class='coded_true itcoded_true'>"+tp_info.elements["info"].cdatas.join.strip+"</li>";
though, since difference between them in class
names, might consider trying determine ahead of time , build markup string afterwards.
var t2_class = ['coded_true']; if (tp_info.attributes["itcoded"] == "true") { t2_class.push('itcoded_true'); } var t2 = "<li class='" + t2_class.join(' ') + "'>"+tp_info.elements["info"].cdatas.join.strip+"</li>"
Comments
Post a Comment