pankaj yadav
pankaj yadav

Reputation: 5

Get the value from array on the basis of another property array in AngularJS

My Arrays are:

var FirstArr=[
              {
                "id":"123",
                "aboutUS":"Demo About Us"
              },
              {
                "id":"234",
                 "tutorial":"Demo Tutorial"
              }
             ];
var SecondArr=[
               {
            data:"aboutUS"
               },
           {
        "data":"toturial"
           }
              ];

I am not getting the value in temp,sTemp as a property is not working and showing undefined.

var sTemp=SecondArr[0].data;

var temp=FirstArr[0].sTemp;

Please Suggest me the solution....

Upvotes: 0

Views: 28

Answers (1)

Daniël Smink
Daniël Smink

Reputation: 368

The error is in your notation you should use [] with a variable property name so

var temp=FirstArr[0][sTemp];

See this plnkr: http://embed.plnkr.co/QY9aWDgxll3PcaO6ZgjN/preview

It console logs the temp value.

Upvotes: 1

Related Questions