Convert Array to Json and deal with null value - Node.js Array

Node.js examples for Array:Convert Array

Description

Convert Array to Json and deal with null value

Demo Code

Array.prototype.toJSON = function(){
  for(var i=0,json=[];i<this.length;i++)
    json[i] = (this[i] != null) ? this[i].toJSON() : "null";
  return "["+json.join(", ")+"]"
}

Related Tutorials