2

I want to access this "code:ENABLE_CO" in angular I have tried, the following code nothing has been worked for me. for your reference i have attached the image, anyone please help me out for this

it is the dynamic one . and i need both the key and value and the structure may differ.

 if(user.authorizations)
        {
           
            user.authorizations.forEach(obj=>
                {
                    for (const [key, value] of Object.entries(obj))
                    {
                        console.log(key);
                        console.log(value);
                        if(value=="ENABLE_COMPANY_CODE")
                        {
                            console.log("value is"+value);
                        }
                    }

                })
            
        }

=

enter image description here

6
  • How does your user.authorizations look like? Commented Apr 22, 2023 at 13:39
  • Please provide the context. Is it a dynamic, changable content, or static? Does it always have the same structure/keyes, but possibly different values? Do you only need the key that has that value, or only the value of that particular key? Commented Apr 22, 2023 at 13:55
  • @AdityaParab this is my user.authorizations, if i console.log(user.authorizations) i got this Commented Apr 22, 2023 at 14:09
  • @MishaMashina it is the dynamic one, i need both key and value. . sturcture will different for different scenerios Commented Apr 22, 2023 at 14:12
  • Then, if you cannot expect that the structure will be the same for each possible object in user.authorizations array (i.e. that it will have screens and functionalities) and you can also have code key in upper-level objects (i.e. not the ones you're looking for), it might be a good idea to use for loops to iterate over objects, then if clause to test it if has screens, then for-loop again to iterate over screens objects and check if they have functionalities, then iterate again through functionalities objects and find the value of the code. Commented Apr 22, 2023 at 14:40

0

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.