How can I, using Javascript, make a function that will trim string passed as argument, to a specified length, also passed as argument. For example:
var strin
Copying Will's comment into an answer, because I found it useful:
var string = "this is a string"; var length = 20; var trimmedString = string.length > length ? string.substring(0, length - 3) + "..." : string;
Thanks Will.
And a jsfiddle for anyone who cares https://jsfiddle.net/t354gw7e/ :)