Nodejs Array Convert toList(separator, aggregator)

Here you can find the source of toList(separator, aggregator)

Method Source Code

Array.prototype.toList = function(separator, aggregator) {
   aggregator = aggregator || separator;
   return this.join(aggregator, [this.join(separator, this.slice(0, -1)), this.slice(-1)]);
};

Related

  1. toHexArray()
    Array.prototype.toHexArray = function() {
        var hex_array = [];
        for (var i=0; i < this.length; i++) {
            var val;
            if (typeof(this[i]) === "string") {
                val = parseInt(this[i], 2).toString(16);
            else if (typeof(this[i]) === "number") {
                val = this[i].toString(16);
    ...
    
  2. toIntArray()
    Array.prototype.toIntArray = function() {
        var int_array = [];
        for (var i=0; i < this.length; i++) {
            var val = parseInt(this[i], 2);
            int_array.push(val);
        return int_array;
    };
    
  3. toInts()
    Array.prototype.toInts = function(){
      return this.map(function(val){
        return parseInt(val, 10);
      });
    };
    
  4. toJSON()
    Array.prototype.toJSON = function(){
        var result = [];
        this.forEach(function(item,index){
            result.push( item.toJSON ? item.toJSON() : item );
        });
        return result;
    
  5. toJson()
    Array.prototype.toJson = function(){
      return JSON.stringify(this);
    };
    
  6. toNumFixed(num)
    Array.prototype.toNumFixed = function (num) {
      for (var i = 0; i < this.length; i++) {
        this[i] = this[i].toNumFixed(num);
      return this;
    
  7. toNumber()
    Array.prototype.toNumber = Array.prototype.toNumber || function () {
      let result;
      this.forEach(digit => {
        let power = 10;
        while (digit >= power) {
          power *= 10;
        result = ((result || 0) * power) + digit;
      });
    ...
    
  8. toNumbers()
    Array.prototype.toNumbers = function() {
      for (var i=0; i<this.length;i++) {
        var val = Number(this[i]);
        if (!isNaN(val)) {
          this[i] = val;
        } else {
          this[i] = 0;
      return this;
    };
    
  9. toNumsOnly()
    Array.prototype.toNumsOnly = function() {
      return this.filter(el => !parseInt(el, 10).isNotNumber());
    };