Nodejs String Sub String from Left left(cnt)

Here you can find the source of left(cnt)

Method Source Code

if(!String.prototype.left){
   String.prototype.left = function(cnt){
      return this.substr(0,cnt);
   };//w w w. ja v  a 2 s.c o m
}

if(!String.prototype.right){
   String.prototype.right = function(cnt){
      return this.substr(this.length - cnt,this.length);
   };
}

Related

  1. left(count)
    String.prototype.left = function(count) {
        if (count >= this.length) {
            return this.toString();
        }else {
            return this.slice(0, count);
    };
    
  2. left(count)
    String.prototype.left = function (count) {
        return this.substring(0, count);
    
  3. left(count)
    String.prototype.left = function(count) {
        var result = "";
        var stringLength = this.length;
        if (count > stringLength) {
            count = stringLength;
        var i;
        for (i = 0; i < count; i += 1) {
            result += this[i];
    ...
    
  4. left(count)
    String.prototype.left = function(count) {
        if (count > this.length) return this.toString();
        return this.substring(0, count);
    };