Posted By

athanassiadis on 09/21/11


Tagged

javascript js textmate strings shorten


Versions (?)

Shorten string in javascript


 / Published in: Other
 

  1. shortenString : function( str, length ){
  2.  
  3. var newStr = str;
  4. var words = str.split('', length + 1);
  5. if( words.length > length){
  6. words.pop();
  7. words.push('...');
  8. newStr = words.join('');
  9. }
  10. return newStr;
  11. }

Report this snippet  

You need to login to post a comment.