Ajax返回一个名字的url

时间:2017-11-03 19:21:11

标签: arrays json ajax

JSON
links {
 name: "card";
 url: "http://google.com";
}



j.each(branch.links, function(i, supportlinks) {                                    
    console.log(supportlinks["card"].url);                                      
    });

如何将其转换为以下内容,并使用名为url的链接输出card

links {     
 card: "http://google.com";
}

1 个答案:

答案 0 :(得分:1)

var result = {};

j.each(branch.links, function(i, supportlinks) {                                    
    supportlinks[supportlinks.name] = supportlinks.url;
});

console.log(result);