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

221
Views
Handle API to not receive value less than 0 (negative values)

I need to treat the API result so that I don't receive values less than 0, I've been trying this way and so far I haven't been able to:

private handleChart(data: Object): void {
    const series = [];

    for (const [key, value] of Object.entries(data)) {
      series.push({
        name: key,
        data: value,
        type: "line",
      });
    }
    
    if (series[0].data.length < 0) {
      delete series[0].data;
    }
    console.log(data );  

    this.plotChart(series);
  }

Original code:

private handleChart(data: Object): void {
    const series = [];

    for (const [key, value] of Object.entries(data)) {
      series.push({
        name: key,
        data: value,
        type: "line",
      });
    }

    this.plotChart(series);
  }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Assuming your data object is:

const obj = {'jan':100,'feb':200, 'mar':-100,'apr':250};

You can filter and map your Object.entries result like:

Object.entries(obj)
  .filter(arr=> +arr[1] >= 0)
  .map(arr=>{return{name:arr[0],data:+arr[1],type:'line'}});

The result would be:

[
 {"name": "jan","data": 100,"type": "line"},
 {"name": "feb","data": 200,"type": "line"},
 {"name": "apr","data": 250,"type": "line"}
]

Or if you want to floor the negative values:

 Object.entries(obj)
   .map(arr=>{return{name:arr[0],data:+arr[1] >= 0 ? +arr[1] : 0,type:'line'}});

Result:

[
 {"name": "jan","data": 100,"type": "line"},
 {"name": "feb","data": 200,"type": "line"},
 {"name": "mar","data": 0,"type": "line"},
 {"name": "apr","data": 250,"type": "line"}
]
about 4 years ago · Juan Pablo Isaza Report
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!