Nodejs String Sub String from Left left(n)

Here you can find the source of left(n)

Method Source Code

/**//from w w  w. j a v  a  2s.c  o  m
 * get a substring of a particular length from the left
 * 
 * @function external:String.prototype.left
 * @param {number}     n     The lenth of the string to return
 * @return {string}
 * @example
 *  'foobar'.left(3) === 'foo'
 */
String.prototype.left = function(n) {
   return this.substr(0,n);
};

Related

  1. left(count)
    String.prototype.left = function (count) {
        return this.substring(0, count);
    
  2. 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];
    ...
    
  3. left(count)
    String.prototype.left = function(count) {
        if (count > this.length) return this.toString();
        return this.substring(0, count);
    };
    
  4. left(i)
    String.prototype.left = function(i)
        if (this.length > i) return this.substr(0, i) + "...";
        return this;
    };
    
  5. left(n)
    String.prototype.left = function(n) {
      return this.substr(0,n)
    
  6. left(n)
    String.prototype.left = function(n) {
        return this.slice(0, n);
    
  7. left(num)
    String.prototype.left = function(num) {
      var result = '';
      for (var i = 0; i < num; i++) {
        result += this[i];
      };
      return result;