Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

cut text if too long javascript

if(snippet.length > 1024) {
text = snippet.substring(0, 1024)//cuts to 1024
last = text.lastIndexOf(" ")//gets last space (to avoid cutting the middle of a word)
text = text.substring(0, last)//cuts from last space (to avoid cutting the middle of a word)
text = text + ` (...)`//adds (...) at the end to show that it's cut
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: js style background image by id 
Javascript :: get input value on keypress jquery 
Javascript :: method domain validator js 
Javascript :: listen prop change vuejs 
Javascript :: cep validator js 
Javascript :: remove string from array in js 
Javascript :: how to loop audio in js 
Javascript :: console group 
Javascript :: sleep in javascript 
Javascript :: react native navigation hide navbar 
Javascript :: javascript foreach key value 
Javascript :: skip mongoose 
Javascript :: fullscreen electron 
Javascript :: create a new input with type checkbox javascript 
Javascript :: javascript reset scroll position 
Javascript :: convert 2 dimensional array to js object 
Javascript :: keyboard arrow event handling javascript 
Javascript :: three.js create sphere 
Javascript :: disable editing ace code edior 
Javascript :: toggle bootstrap modal with jquery 
Javascript :: on load hit click event js 
Javascript :: navigate to route and refresh angular 6 
Javascript :: jquery change font color 
Javascript :: set onclick javascript 
Javascript :: javascript sort array by A-Z in js 
Javascript :: upload files in react using axios 
Javascript :: m- m sequelize 
Javascript :: randome words api 
Javascript :: activate es6 module node package.json 
Javascript :: javascript change element class 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =