Converting a 2D array to a JSON list
Here's what I've come up with;

import expect from 'expect';

const is2dArrayParsableToJsonList = () =&gt; true;

const convert2dArrayToJsonList = (array) =&gt; {

    if (!is2dArrayParsableToJsonList(array)) {
        throw new Error("The 2D array cannot be converted to a json list" + array);
    }

    const [propertyKeys, ...rows] = array;
    const rowToObject = row =&gt; Object.assign(... propertyKeys.map( (key,idx) =&gt; ({ [key]: row[idx] })));
    return rows.map(rowToObject);
}

const input = [
    ['foo', 'bar', 'baz'],
    [1,2,3],
    [4,5,6]
];

const output = [
    {foo:1, bar:2, baz:3},
    {foo:4, bar:5, baz:6},
];

expect(convert2dArrayToJsonList(input)).toEqual(output);


Core idea is that map gives you both a value and index. So when you map over the keys, we see 'foo/1', 'bar/2', 'baz/3'.