javascript - convert ajax response into a particular format? -
enter image description here input: var result= json.parse(response); console.log(result);
given below output of console.log(result); want convert given below output want this.
output: {day: array(7), amount: array(7)} amount: (7) [413, 14, 2, 37, 50, 22, 82] day: (7) ["02-jan-16", "03-jan-16", "04-jan-16", "05-jan-16", "06-jan-16", "07-jan-16", "08-jan-16"] input ajax response data. want convert response data particular format describe below. output should this. how can this? output want: [[02-jan-16,413],[03-jan-16,14],[04-jan-16,2],[05-jan-16,37], [06-jan- 16,50],[07-jan-16,22],[08-jan-16,82]]
enter image description here output image. check out.
you map wanted values new array.
function getdata(object) { return data.amount.map(function(a, i) { return [object.day[i], a]; }); } var data = { amount: [413, 14, 2, 37, 50, 22, 82], day: ["02-jan-16", "03-jan-16", "04-jan-16", "05-jan-16", "06-jan-16", "07-jan-16", "08-jan-16"] }, result = getdata(data); console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }
Comments
Post a Comment