Supply an array of keys and map over an array of structured data. If the array is a matrix (2-dimensional array), it will produce an array of objects with the keys taking the values at the respective index; if it consists of objects, the selected keys produce an array of those values:
const fields = [
['Your Name', 'username', 'text' ],
['Email address', 'email', 'text' ],
['Password', 'Password', 'Password'],
]
const inputs = fields.map(matrix(['label', 'name', 'type']))
// 👇 Arrays are transformed into objects with keys assigned by index
//
// {label: 'Your Name', name: 'username', type: 'text' },
// {label: 'Email address', name: 'email', type: 'text' },
// {label: 'Password', name: 'Password', type: 'Password'},
inputs.map(matrix(['name', 'label', 'type']))
// 👇 Objects are transformed into arrays with keyed properties in the given ordered
//
// ['username', 'Your Name', 'text' ],
// ['email', 'Email address', 'text' ],
// ['Password', 'Password', 'Password'],
inputs.map(matrix(['name', 'type']))
// 👇 Keys can be omitted to extract only pertinent data
//
// ['username', 'text' ],
// ['email', 'text' ],
// ['Password', 'Password'],
fields.map(matrix([,'name', 'type'))
// 👇 The same can be achieved for matrices by leaving empty slots at the relevant indices in the keys array
//
// {name: 'username', type: 'text' },
// {name: 'email', type: 'text' },
// {name: 'Password', type: 'Password'},