i have json server fake data in my react app and here is my data:
{"quotes": [
{
"id": 1,
"quote": "Javascript is my life",
"author": "ali pasha",
"comments": [],
},
{
"id": 2,
"quote": "Learning react is very fun",
"author": "nasim rabiei",
"comments": []
}],}
this app is a quotes showing app that each quote has comments. in my quote form users can send comment but i can not access to the comments propery to send data. how can i access to this specific propery and fill it with comments that recive from users?
Edite:
i expercted get comments data with a http request, fo example http://localhost:3001/quotes/1/commnets => give me data of comments for quote 1
3
Answers
Since quotes is an array of object and comments is array as well so to access the comments you will have to use array indexing or you can loop through the comments since it is an array
For your API endpoint
/quotes/1/commnets
you can create a methodgetQuoteCommentsById(id)
using Array.prototype.find() and remember to handle "Not found errors"Code: