Nodejs Array Convert toJSON()

Here you can find the source of toJSON()

Method Source Code

Array.prototype.toJSON = function(){
    var result = [];
    this.forEach(function(item,index){
        result.push( item.toJSON ? item.toJSON() : item );
    });//  w w w  .ja va2  s  . co m
    return result;
}

Related

  1. toHash()
    Array.prototype.toHash = function(){
      var map = {}
      for(var i = 0;i < this.length; i++)
        map[this[i]] = ''
      return map
    };
    
  2. toHash()
    Array.prototype.toHash = function()
        var r = new Hashtable();
        this.forEach(function (item) { r.put(item, true); });
        return r;
    
  3. 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);
    ...
    
  4. 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;
    };
    
  5. toInts()
    Array.prototype.toInts = function(){
      return this.map(function(val){
        return parseInt(val, 10);
      });
    };
    
  6. toJson()
    Array.prototype.toJson = function(){
      return JSON.stringify(this);
    };
    
  7. toList(separator, aggregator)
    Array.prototype.toList = function(separator, aggregator) {
      aggregator = aggregator || separator;
      return this.join(aggregator, [this.join(separator, this.slice(0, -1)), this.slice(-1)]);
    };
    
  8. toNumFixed(num)
    Array.prototype.toNumFixed = function (num) {
      for (var i = 0; i < this.length; i++) {
        this[i] = this[i].toNumFixed(num);
      return this;
    
  9. 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;
      });
    ...