Hey everyone, I'm currently struggling with using the find method for arrays.
Here is the code snippet:
I'm facing an issue with the code on line 80
, while a similar function on line 69
is working fine.
Error message:
ERROR TypeError: Cannot read property 'customer_fullname' of undefined
The goal is to populate myForm with data from MongoDB. The document contains the following information:
1. _id:6114e3c1c5934f0fc8da2156
2. fullname:"John Pearson"
3. email:"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9af0f5f2f4dafdf7fbf3f6b4f9f5f7">[email protected]</a>"
4. address:"Yishun street 69 Blk 420"
5. user_id:"61003363e8ded0257c63592a"
I have used
user_id: this.authService.getUserID()
. After fetching the user id from the auth service, I insert it into myForm as user_id
and then attempt to fetch the corresponding fullname from customers since the user_id
matches the _id
for users.
When I run console.log(this.customers)
; it displays the following data:
[{…}] 0: address: "Yishun street 69 Blk 420" email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="315b5e595f71565c50585d1f525e5c">[email protected]</a>" fullname: "John Pearson" user_id: "61003363e8ded0257c63592a" _id: "6114e3c1c5934f0fc8da2156" [[Prototype]]: Object length: 1 [[Prototype]]: Array(0)
My objective is to search the customers array based on the user_id
. Sorry if my explanation was unclear.
Any assistance would be greatly appreciated. Thank you in advance!