0

I am working on a React frontend with a delete method which deletes an item in the database. Having a hard time with the following code.

deleteFromDB = idTodelete => { let objIdToDelete = null; this.state.data.forEach(dat => { if (dat.id == idTodelete) { objIdToDelete = dat._id; } }); 

This is the method called after entering the ID to be deleted and this modifies the state by deleting the item corresponding to the ID

2
  • This could be a typo, but maybe the objects in your state have two ID attributes. id might be a 'frontend' ID whereas _id is the ID used in the database. Commented May 10, 2019 at 9:42
  • Possible duplicate of What is the underscore "_" in JavaScript? Commented May 10, 2019 at 9:56

2 Answers 2

3

It's a naming convention for private variables and methods used by some developers to indicate that they are private.

Also see: What is the underscore "_" in JavaScript?

Sign up to request clarification or add additional context in comments.

Comments

1

It may be possible that _id is actually the primary key of the data you want to delete, as it is actually used in mongodb

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.