I have one array of objects, these objects have a timestamp attribute, I want to calculate the duration from the time stamp:
myArray = [obj1, obj2, obj3];
ob1 = {"attr1":val1, "attr2":val2, "timestamp": ...};
I want to get the duration between consecutive objects: (in python it would look a bit like this:
durations = myArray[1:]-myArray[:-1])
>Solution :
You can slice the array to get a copy without the first element, then apply map over it.
let durationDiffs = myArray.slice(1).map((x, i) => x.timestamp - myArray[i].timestamp);