score:1

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"}
]

Related Articles