0
userdata:any[];
    
this.auth.getapicall().subscribe(datareturn=>{
            console.log(datareturn.message);
            this.userdata=datareturn;

I am calling an api with get method and store its data in "datareturn". I have stored the result in array of userdata. if I console the userdata it returns the results but I am unable to understand that how to access the data inside userdata. Here is the console data snapshot....

Here is console result

{data: Array(1), pageinfo: {…}, message: "Success", submessage: "Success"}
data: Array(1)
0: {id: "5fd881a754315ca43cf4af48", account_id: "5fce31a454315ca43cf4af31", user_id: "5fce31a454315ca43cf4af32", name: "aamaadmi", is_custom: true, …}
length: 1
__proto__: Array(0)
message: "Success"
pageinfo: {page: 1, limit: 25, total_count: 1}
submessage: "Success"
__proto__: Object
1
  • Have you tried this.userdata = datareturn.message?.data? Commented Dec 22, 2020 at 8:16

2 Answers 2

1

The console result shows only one array - the data property. So if the console log is resulted from logging datareturn.message then you can access your array with datareturn.message?.data like below -

this.auth.getapicall().subscribe(
    datareturn => {
        this.userdata = datareturn.message?.data;
    });
Sign up to request clarification or add additional context in comments.

Comments

1

If looking your api response it seems you are having three items

  1. data
  2. message
  3. submessage

Your needed information is in data so you must code like

this.userdata = datareturn.data

Try this.

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.