0

im using axios to fetch data form an api. and to make delete request.

here is what the array looks like: array

i can get this array by using

const { data } = await axios.get('http://ipadress:5000/api/categories/61cae5daf5bfbebd7cf748ee')

and delete it using:

await axios.delete(`/api/categories/${61cae5daf5bfbebd7cf748ee}`)

my qeustion is how can i delete one object from the array. for example the 'Jewelry' object.

1 Answer 1

1

You need to get a different API to delete the item from the nested array something like this;

await axios.delete(`/api/categories/subcategory/${61......fo}/`)
Sign up to request clarification or add additional context in comments.

2 Comments

is there a different way for example a filtering method before the delete. to delete object based on id. instead of creating a sperate route of sub category. thanks
@shanksu218 - I think you are asking about this let id = obj.SubCats.find((SubCat)=>SubCat.name ==="Jewelry").id find will return an object on the other hand filter will return an array if you have multiple names with same key you can use filter then loop over the ids and delete those ids

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.