Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
How to check object value unchanged based on timestamp?

I have an object with Timeseries and a value for showing a chart. The value updates often. I want to display the number of hours the value is unchanged.

For example: consider the below object, the value remains the same for some hours. I want to show how many hours it is unchanged. If any new value is different then want to update the hours to Zero.

obj = [{
  "value": 48.52062,
  "timestamp": 1652848223325
},
{
  "value": 48.52062,
  "timestamp": 1652838323281
},
{
  "value": 48.52062,
  "timestamp": 1652833823275
},
{
  "value": 51.71021,
  "timestamp": 1652830223280
},
{
  "value": 48.52062,
  "timestamp": 1652829323276
}]

I am trying to filter the object using obj.filter(e => e.value === 48.52062) and check that filtered object timestamps and calculate the hours of first object and last object timestamp

But, the filtered object returns even the old data, in this case, the data value is changed in between which is not a flatline. I just want to check only until the value last changed.

I am not sure, if this is the right way to do it. Here is the code:

var obj = [{
  "value": 48.52062,
  "timestamp": 1652848223325
},
{
  "value": 48.52062,
  "timestamp": 1652838323281
},
{
  "value": 48.52062,
  "timestamp": 1652833823275
},
{
  "value": 51.71021,
  "timestamp": 1652830223280
},
{
  "value": 48.52062,
  "timestamp": 1652829323276
}];

const x = obj.filter(e => e.value === 48.52062)
const timeStart = x[0].timestamp;
const timeEnd = x[x.length - 1].timestamp;


console.log(getHourDiff(timeStart, timeEnd));

function getHourDiff(start, end) {
   return Math.floor((end - start) / 3600000)
}

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!