I am trying to filter through an array of objects and delete one of the object but keep the rest inside an array of objects but i keep returning either an array of arrays or i create nested objects. Is it possible to send in an array of objects and return and array of objects without that specific object? Below is the code I have been trying to work with.
function deleteWorkout(workoutName) {
const updatedArray = myWorkoutToDisplay.map((item) => item.newWorkToAdd.filter((workout) => workout.name !== workoutName))
const objectArray = [{updatedArray}]
const newWorkToAdd = objectArray.filter(e => e.length)
const workouts = [{newWorkToAdd}]
setMyWorkoutToDisplay(updatedArray)
}
myWorkoutToDisplayis ornewWorkToAddis for certain."workoutToAdd": [ { "name": "1\nKettlebell Slingshot (Kettlebell Around the World)", "image": "https://kettlebellsworkouts.com/wp-content/uploads/2018/08/01_kettlebell-slingshot.png" }, { "name": "2\nKettlebell Halo", "image": "https://kettlebellsworkouts.com/wp-content/uploads/2018/08/02_kettlebell-halo.png" }]