json2array.js
February 15, 2021•69 words
/**
* Copyright Alicia Sykes <https://aliciasykes.com>
* Licensed under MIT X11: https://git.io/Jew4i
*
* Converts a given JSON object into an array
* Where { key: 'Value' } --> ['key': 'value']
* @param json - the object to be converted
*/
const json2array = (json) => {
const result = [];
const keys = Object.keys(json);
keys.forEach((key) => {
result.push({ key, value: json[key] });
});
return result;
};