Noob need help with sorting an array

So i have an array with two objects like this:

Array(4)
0:{Activity: “Skiing”, Duration: 74}
1:{Activity: “Strength training”, Duration: 64}
2:{Activity: “Cycling”, Duration: 64}
3:{Activity: “Running”, Duration: 43}

The input is coming from a user which selects one out of four different activities, and then write how long the workout lasted.

And what i want to do is to sort them in a way that sums the “duration” instead of makeing a new array element.

So if the user inputs “activity” and “Duration” the array will find the right activity and increase the duration to give a total duration.
For instance if

“activity”: “skiing”, “Duration”= 10

Would update Duration to " 84"

Array(4)
0:{Activity: “Skiing”, Duration: 84}
1:{Activity: “Strength training”, Duration: 64}
2:{Activity: “Cycling”, Duration: 64}
3:{Activity: “Running”, Duration: 43}

I would appreciate it a lot if somebody could help me.

Sounds like you need to find the index of the relevant object, and change its .Duration …

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.