javascript - Escape all attributes of an object -


how can escape attributes of object in js?

var literal = {     valid:'thisisavalidvalue',      toescape:'thîsstringnéédstobéescàped' };  //does not work escape(literal)  //does not work either, how loop on attributes? $.each(literal.attributes, function(){    = escape(this); }); 

first, really sure want escape? it's old, deprecated function.

but in case, form of code doesn't change, regardless function call transform values:

var key; (key in literal) {     literal[key] = escape(literal[key]); } 

or using jquery's $.each, since seem using jquery:

$.each(literal, function(key, value) {     literal[key] = escape(value); }); 

if want sure not process inherited properties (although literal won't have enumerable inherited properties unless has been naughty indeed , added enumerable property object.prototype):

var key; (key in literal) {     if (literal.hasownproperty(key)) {         literal[key] = escape(literal[key]);     } } 

more for-in on blog: myths , realities of for..in