Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Break the string into two lines

I want to break a string into two lines, but the line should not break into two, at the half of a word. How can I do this?

The string format is like this:

var words="value.eight.seven.six.five.four.three"

Expected output is:

"value.eight.seven.

six.five.four.three"
like image 823
Krishna Avatar asked Jun 26 '14 05:06

Krishna


1 Answers

Try,

var words = "value.eight.seven.six.five.four.three";
var splitted = words.split('.');
var index = splitted.length / 2;  
var val1 = splitted.slice(0, index).join('.') + ".";
var val2 = splitted.slice(index, splitted.length).join('.');

DEMO

like image 113
Rajaprabhu Aravindasamy Avatar answered Oct 13 '22 05:10

Rajaprabhu Aravindasamy