Javascript object notation -
i did manipulations , stored values in arrays say, miles , type. need display object own specific properties. have
obj ={ "miles" : [500,200], "type": ["fer","bug"] };
i need return object in format
obj = { "fer" : 500 , "bug" : 200 };
thanks. idea appreciated!
iterate , create new object
var obj = { "miles" : [500,200], "type": ["fer","bug"] }; var obj2 = {}; (var i=0; i<obj.type.length; i++) { obj2[obj.type[i]] = obj.miles[i]; } // snippet output document.body.innerhtml = '<pre>' + json.stringify(obj2, null, 4) + '</pre>';
Comments
Post a Comment