Get specific object by id from array of objects in AngularJS

前端 未结 17 1403
囚心锁ツ
囚心锁ツ 2020-12-07 07:20

I have a JSON file containing some data I d like to access on my AngularJS website. Now what I want is to get only one object from the array. So I d like for example Item wi

17条回答
  •  轮回少年
    2020-12-07 08:18

    I would iterate over the results array using an angularjs filter like this:

    var foundResultObject = getObjectFromResultsList(results, 1);

    function getObjectFromResultsList(results, resultIdToRetrieve) {
            return $filter('filter')(results, { id: resultIdToRetrieve }, true)[0];
        }
    

提交回复
热议问题