OK, I have a JavaScript created section on a page and I want to return a summary only not the entire text. i.e. first 50 whole words and as ive mentioned before, JavaScript isnt my thing but it has to be JS not Jquery.
I have written the script but it returns unexpected results so would be grateful if someone could take a look and point out where Im going wrong.
My code:
var ap = document.createElement("P");
var stext = value[i].Summary.split(" ", 50)
ap.appendChild(document.createTextNode(stext));
ar.appendChild(ap);
Which returns:
Lorem,ipsum,dolor,sit,amet,,consectetur,adipisicing,elit,,sed,do,eiusmod ,tempor,incididunt,ut,labore,et,dolore,magna,aliqua.,Ut,enim,ad,minim, veniam,,quis,nostrud,exercitation,ullamco,laboris,nisi,ut,aliquip,ex,ea, commodo,consequat.,Duis,aute,irure,dolor,in,reprehenderit,in,voluptate, velit,esse,cillum,dolore,eu,fugiat
What I want to return is:
Lorem ipsum dolor sit amet consectetur adipisicing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat
value[i].Summary.split(" ", 50).replace(',',' ')
– Bharadwaj.join(' ')
after your split. (also dont forget the closing;
on that line – haxxxton