Nodejs String Sub String from Left left(count)

Here you can find the source of left(count)

Method Source Code

String.prototype.left = function(count) {
    var result = "";

    var stringLength = this.length;

    if (count > stringLength) {
        count = stringLength;//from ww  w .j ava 2  s .  c o  m
    }

    var i;
    for (i = 0; i < count; i += 1) {
        result += this[i];
    }

    return result;
};

Related

  1. left(cnt)
    if(!String.prototype.left){
      String.prototype.left = function(cnt){
        return this.substr(0,cnt);
      };
    if(!String.prototype.right){
      String.prototype.right = function(cnt){
        return this.substr(this.length - cnt,this.length);
      };
    ...
    
  2. left(count)
    String.prototype.left = function(count) {
        if (count >= this.length) {
            return this.toString();
        }else {
            return this.slice(0, count);
    };
    
  3. left(count)
    String.prototype.left = function (count) {
        return this.substring(0, count);
    
  4. left(count)
    String.prototype.left = function(count) {
        if (count > this.length) return this.toString();
        return this.substring(0, count);
    };
    
  5. left(i)
    String.prototype.left = function(i)
        if (this.length > i) return this.substr(0, i) + "...";
        return this;
    };
    
  6. left(n)
    String.prototype.left = function(n) {
      return this.substr(0,n)
    
  7. left(n)
    String.prototype.left = function(n) {
      return this.substr(0,n);
    };