Maison > Questions et réponses > le corps du texte
场景:使用js调用了外部接口方法
function(res){
//res为调用这个方法返回的对象
}
如何解析res这个对象,取得res这个对象的所有属性?
天蓬老师2017-04-10 17:13:14
var obj = {
'name':'lao wang',
'gender':'male',
'age':48,
'speak':function(){
console.log('hello , I\'m lao wang');
}
}
function analyze(o){
for(var key in o){
console.log(key + ':' + o[key]);
}
}
analyze(obj);
巴扎黑2017-04-10 17:13:14
function(res) {
Object.keys(res).forEach(function(key) {
// 取得全部属性!
console.log(res[key]);
});
}