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"
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('.');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With