How to remove a substring from JavaScript object?
I am wo开发者_如何学运维rking with JavaScript for a project where I have been using a function like below for having a string output.
function formatObject(obj){
var obj;
var s="";
$.each(obj,function(k,v) { s = s+k+"="+v+"&"; });
return s
return JSON.stringify(obj).replace(/,/g,',\n__events__ ').replace('{','{\n ').replace('}','\n}')
}
And out put of formatObject(obj)
having an extra
__events__=function () {}
I am confused how I should remove this unwanted keyword from my output.
Just skip it when you're building the string:
$.each(obj, function(k, v) { if (k != '__events__') s = s + k + '=' + v + '&'; });
精彩评论