/ Published in: JavaScript
Parameters: required **[string]**, optional **[number of lines]**.
By default it breaks the string passed into 3 lines.
It takes a string and converts it to an array of strings, splitting the original string into smaller parts (useful for word breaking).
By default it breaks the string passed into 3 lines.
It takes a string and converts it to an array of strings, splitting the original string into smaller parts (useful for word breaking).
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var lineSplit = function(str, lines){ lines = lines || 3; var strArr = str.split(" "), cropSize = Math.ceil(strArr.length / lines), splitted = []; while(strArr.length){ splitted.push(strArr.splice(0, cropSize).join(" ")); } return splitted; };