I have this array of nested objects and arrays:
const myArr = [
{
workoutName: "workout1",
exercises: [
{
exerciseName: "Bench Press",
sets: [
{
// some props and vals
},
]
},
{
exerciseName: "Deadlift",
sets: [
{
// some props and vals
},
]
},
{
exerciseName: "Squat",
sets: [
{
// some props and vals
},
]
},
// more exercises
]
}
]
const compareVal = "Deadlift";
const mySetObj = {//some data}
I want to iterate through the exercises array of objects and compare the exerciseName value for each object with the compareVal for a match. If it does match, I want to be able to add myObj as a value to that object's setsarray. Each of the exerciseName values are unique, so it would not be necessary to iterate through all of the exercises after finding a match.
Is there a way I can achieve this elegantly?
myArris an array itself. Do you need to do this for each workout routine, or just formyArr[0]?