JSFiddle - React, Tailwind, and code Playground

by ramnathv

JavaScript

var stocks = [{"time":"2009-01-01","X":-0.0424,"Y":-2.2632,"Z":-5.7731},{"time":"2009-01-02","X":1.1545,"Y":0.6761,"Z":5.1898},{"time":"2009-01-03","X":-1.4025,"Y":-1.0838,"Z":-4.6046},{"time":"2009-01-04","X":-0.2367,"Y":5.0445,"Z":6.9573},{"time":"2009-01-05","X":-0.2143,"Y":-0.1152,"Z":-0.4997},{"time":"2009-01-06","X":1.1973,"Y":-2.8187,"Z":-0.8234},{"time":"2009-01-07","X":-0.8058,"Y":-0.0445,"Z":4.7107},{"time":"2009-01-08","X":-0.2959,"Y":-2.3662,"Z":2.6402},{"time":"2009-01-09","X":0.7179,"Y":-2.0901,"Z":-0.3231},{"time":"2009-01-10","X":1.2906,"Y":-0.1546,"Z":2.258}]

function gather_row(row, key, value, keep){
  Object.keys(row).forEach(function(k){
    var arr = {}
    if (keep.indexOf(k) < 0){
        arr.push({key: k, value: row[k]})        
    }
  })
}
      
gather_row(stocks[0], 'key', 'value', ['time'])