user3812457
user3812457

Reputation: 157

How can i compare the two objectes data in angularjs

I have two json objects in controller ,how can i match the id of first object with second json object id in angularjs first json:

$scope.fetchAllCenters= [
        {
            "sid": 1,
            "group": "Group 1",
            "name": "Item 1"
        },
        {
            "sid": 2,
            "group": "Group 1",
            "name": "Item 2"
         },
        { "sid":3,
         "group":"Group2",
         "name":"Item 3"
        },


    ];

second json data:

$scope.myData = [{name: "Moroni", id: 1},
                     {name: "Tiancum", id: 2},
                     {name: "Jacob", id: 3},
                     {name: "Nephi", id: 4},
                     {name: "Enos", id: 5}];

how can i compare sid of first with object data is matched with idof second object data in angularjs

Upvotes: 0

Views: 1497

Answers (1)

sylwester
sylwester

Reputation: 16498

if ($scope.fetchAllCenters[0].sid === $scope.myData[1].id) 
{
alert("sid of first fetchAllCenters is equat to id of myData ");
}

Upvotes: 1

Related Questions