0

How to access value of userPass from array of object using angular 7?

I need to access Property userPass value from array of object

I have variable type any his name auth

auth have array of object

I need to access property value of userpass from json below

var auth;
auth =  


    [{"userLoginID":0,"userName":"test","userMail":"[email protected]","userPass":"12345678","fkTeamID":0  

    ,"isAdmin":false,"createdBy":0,"createdDate":"0001-01-01T00:00:00","isHidden":false}]  

I need to access userPass value meaning i need to access 12345678

what i try is

ngOnInit() {


     auth.forEach(element => {
      element.forEach(au => {
         console.log(au.userPass);

      });
      });
     userpathvalue=???
      }

Meaning i need to access value 12345678

2
  • Does this answer your question? accessing field value in array of objects in javascript Commented Jan 12, 2020 at 2:19
  • You have a single array. Why would you need two loops? auth[0].userPass is the userPass of the first object in the array. If you want to access the userPass of every element, use a loop: auth.forEach(element => console.log(element.userPass)) Commented Jan 12, 2020 at 15:06

1 Answer 1

1

Since length of your array is one, so then this code is enough to get value.

auth[0].userPass

So, If you do :

console.log(auth[0].userPass)

It will print "12345678"

*Note: This solution is only for your specific case because you have the length of your array is one, if more then you have to loop through.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.