set length of string javascript code example

Example 1: javascript string lentrh

var myString = "string test";
var stringLength = myString.length;

console.log(stringLength); // Will return 11 because myString 
// 							  is 11 characters long...

Example 2: length of string in javascript

var str = "Hello World!";
var n = str.length;

Example 3: javascript set max length of string

String.prototype.trimEllip = function (length) {
  return this.length > length ? this.substring(0, length) + "..." : this;
}

Tags:

Cpp Example