I have a javascript array that contains objectiveDetail objects.
objectiveDetails[]
Here I am adding a new objectiveDetail:
var emptyObjectiveDetail = {
"number": formData.objectiveDetails.length +1, // I want to change this !
"text": "",
"response": false,
"objectiveId": formData.objectiveId
};
objectiveDetails.push(emptyObjectiveDetail);
How can I make it so that the number I assign to the emptyObjectDetail field is equal to the greatest number currently used by the objectiveDetail objects in the array.
In other words if I have three objectiveDetail objects with the "number" field set to 1, 4 and 5 then when I add a new object I would like to add it with the number 6 instead of the length of the array + 1
I'm also interested in using _underscore and would like to know if there is a good way to do this with underscore as well as javascript