Skip to content

Instantly share code, notes, and snippets.

@RCrowt
Last active October 5, 2016 08:12
Show Gist options
  • Select an option

  • Save RCrowt/d3c4423ab2e51222cec3dbe7301c3c3b to your computer and use it in GitHub Desktop.

Select an option

Save RCrowt/d3c4423ab2e51222cec3dbe7301c3c3b to your computer and use it in GitHub Desktop.
/**
* Convert a multidimensional array/object to a single dimenstion object.
* @param data {array|object} Input data.
* @param prefix {string} key prefix.
*/
var fn_dotArray = function (data, prefix) {
var out = {};
$.each(data, function (k, v) {
if (v !== null && typeof v == 'object') {
$.extend(out, fn_dotArray(v, prefix + k + '.'));
} else {
out[prefix + k] = v;
}
});
return out;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment