Skip to content

Instantly share code, notes, and snippets.

@think49
Created October 1, 2010 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save think49/605932 to your computer and use it in GitHub Desktop.
Save think49/605932 to your computer and use it in GitHub Desktop.
dumpObject.js : オブジェクトを整形文字列にして返します。
// dumpObject.js
// オブジェクトを整形文字列にして返します
function dumpObject (obj) {
var p, result;
result = [];
for (p in obj) {
if (obj.hasOwnProperty(p)) {
result.push(' ' + p + ': "' + obj[p] + '"');
}
}
return '{\n' + result.join(',\n') + '\n}\n';
}
alert(dumpObject({a:'value a', b:'value b', c:'value c'}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment