gpt4 book ai didi

javascript - 从数组结果中获取两个字段

转载 作者:行者123 更新时间:2023-11-30 08:33:22 25 4
gpt4 key购买 nike

我的服务给出的结果如下

$scope.ListOfPeople = [
{ PersonID: 10, FirstName: "John", LastName: "Smith", Sex: "Male" },
{ PersonID: 11, FirstName: "James", LastName: "Last", Sex: "Male" },
{ PersonID: 12, FirstName: "Mary", LastName: "Heart", Sex: "Female" },
{ PersonID: 13, FirstName: "Sandra", LastName: "Goldsmith", Sex: "Female" },
{ PersonID: 14, FirstName: "Shaun", LastName: "Sheep", Sex: "Male" },
{ PersonID: 15, FirstName: "Nicola", LastName: "Smith", Sex: "Male" }
];

我需要按如下方式自定义我的数据源

$scope.output= [
{ PersonID: 10, FirstName: "John" },
{ PersonID: 11, FirstName: "James" },
{ PersonID: 12, FirstName: "Mary" },
{ PersonID: 13, FirstName: "Sandra" },
{ PersonID: 14, FirstName: "Shaun" },
{ PersonID: 15, FirstName: "Nicola" }
];

在 angularjs 中执行此操作的最佳方法是什么

最佳答案

您可以使用 map 来实现您的目标。考虑到 map 创建了新数组。

$scope.output = $scope.ListOfPeople.map(function(item){
return {
PersonID: item.PersonID,
FirstName: item.FirstName
};
});

关于javascript - 从数组结果中获取两个字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34649563/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com