let data = {"classA":[{"date":"01-01","present":49,"absent":14},{"date":"02-01","present":39,"absent":24},{"date":"03-01","present":35,"absent":28}],"classB":[{"date":"01-01","present":49,"absent":14},{"date":"02-01","present":39,"absent":24},{"date":"03-01","present":35,"absent":28}],"classC":[{"date":"01-01","present":49,"absent":14},{"date":"02-01","present":39,"absent":24},{"date":"03-01","present":35,"absent":28}]} let newData = []; for (let [key, value] of Object.entries(data)) { newData.push({class:key, ...value[value.length - 1]}); } console.log(newData);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter