Skip to content

fold

Given a JSON object where the data values and headers have been split into separate key lookups, this function will combine the data values with the headers and returns one large array of objects.

Zips the flat headers array against each row of data, emitting one object per row keyed by header — the first row becomes {year: 2020, apples: 5, bananas: 8}.

import {fold} from "@d3plus/data";

fold({
  headers: ["year", "apples", "bananas"],
  data: [
    [2020, 5, 8],
    [2021, 7, 6],
  ],
});

Parameters

import {fold} from "@d3plus/data";
jsonrequiredFoldableJSON

A JSON data Object with data and headers keys.

datastringDefault data

The key in the JSON object that contains the data array.

headersstringDefault headers

The key used for the flat headers array inside of the JSON object.