我在使用 jquery 获取对象数组中的所有元素时遇到问题...
我从互联网上获取此代码...
var id = 123;
var test = new Object();
test.Identification = id;
test.Group = "users";
test.Persons = new Array();
test.Persons.push({"FirstName":" AA ","LastName":"LA"});
test.Persons.push({"FirstName":" BB ","LastName":"LBB"});
test.Persons.push({"FirstName":" CC","LastName":"LC"});
test.Persons.push({"FirstName":" DD","LastName":"LD"});
如何使用 JQuery 获取 Persons 中的每个“FirstName”和“LastName”?
最佳答案
您可以使用 $.each()
或 $.map()
,具体取决于您想用它做什么。
$.map(Persons, function(person) {
return person.LastName + ", " + person.FirstName;
});
// -> ["Doe, John", "Appleseed, Marc", …]
关于jquery - 如何使用jquery获取对象的值数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4710965/