Skip to content

Instantly share code, notes, and snippets.

@jhsuZerion
jhsuZerion / subform_to_multi_array.js
Created August 25, 2017 17:57
Convert a subform to a multi-dimensional array specified by the second parameter
/**
* function returns subform as 2D array
* @param {object} r valid JSON object
* @param {int} n integer greater than 1
* @return {object} 2D array where number of objects per row is equal to n
*/
function subform_to_multi_array(r,n) {
if(typeof n !== 'number' || n !== Math.floor(n) || n <= 1 || n > r.length) return r;
var cols = [];
var count = 0;