Skip to content

Instantly share code, notes, and snippets.



Created May 11, 2020
What would you like to do?
* Unpivots the given data
* More:
* @return Unpivoted data from array
* @param {object[][]} arr 2D Input Array
* @param {object[][]=} headers [optional] Custom headers for output
* @customfunction
function unpivot(arr, headers) {
const custHeader = arr.shift();
const out = arr.flatMap(([sale, ...qty]) =>, i) => [custHeader[i], sale, num])
if (headers) out.unshift(headers[0]);
return out;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment