-2
[{
    "call_time": "0",
    "total_inc_traffic": "1363.10",
    "total_out_traffic": "88.70"
}, {
    "call_time": "1",
    "total_inc_traffic": "479.57",
    "total_out_traffic": "36.98"
}, {
    "call_time": "2",
    "total_inc_traffic": "239.57",
    "total_out_traffic": "13.43"
}, {
    "call_time": "3",
    "total_inc_traffic": "190.28",
    "total_out_traffic": "8.20"
}, {
    "call_time": "4",
    "total_inc_traffic": "223.80",
    "total_out_traffic": "0.00"
}, {
    "call_time": "5",
    "total_inc_traffic": "158.87",
    "total_out_traffic": "19.58"
}]

this is the url I want to get the output of all the "total_inc_traffic" output as

{1363.10,479.57,239.57,190.28,158.87}

how to get this output using json?

Emma
  • 27,428
  • 11
  • 44
  • 69
  • Easiest but not efficient: foreach the data, collect all total_inc_traffic values into a new array. – paskl Jun 19 '19 at 04:22
  • 2
    Welcome to Stack Overflow! Please take the [tour](https://stackoverflow.com/tour), look around, and read through the [Help Center](https://stackoverflow.com/help), in particular [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) If you run into a specific problem, research it thoroughly, search thoroughly here, and if you're still stuck post your code and a description of the problem. Also, remember to include [Minimum, Complete, Verifiable Example](https://stackoverflow.com/help/mcve). People will be glad to help – Andreas Jun 19 '19 at 04:24

1 Answers1

-1

You can use Array.map and Number

let arr = [{ "call_time": "0", "total_inc_traffic": "1363.10", "total_out_traffic": "88.70" }, { "call_time": "1", "total_inc_traffic": "479.57", "total_out_traffic": "36.98" }, { "call_time": "2", "total_inc_traffic": "239.57", "total_out_traffic": "13.43" }, { "call_time": "3", "total_inc_traffic": "190.28", "total_out_traffic": "8.20" }, { "call_time": "4", "total_inc_traffic": "223.80", "total_out_traffic": "0.00" }, { "call_time": "5", "total_inc_traffic": "158.87", "total_out_traffic": "19.58" }];

let result = arr.map(v => Number(v.total_inc_traffic));
console.log(result);
Nikhil Aggarwal
  • 28,197
  • 4
  • 43
  • 59