2020-11-17 11:16:34 +00:00
|
|
|
/**
|
|
|
|
* Create an array from an Object using specified fields
|
|
|
|
* @param jsonObj The Original object
|
|
|
|
* @param wantedFields The required fields
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* U.arrayFromObj({ a: 1, b: 2 }, ['a', 'b']) // => [1, 2]
|
|
|
|
*/
|
2023-04-30 16:32:28 +00:00
|
|
|
export function arrayFromObj(jsonObj: object, wantedFields: string[]): any[] {
|
2020-11-17 11:16:34 +00:00
|
|
|
return wantedFields.map((key) => {
|
|
|
|
if (jsonObj.hasOwnProperty(key)) {
|
|
|
|
const { value }: any = Object.getOwnPropertyDescriptor(jsonObj, key);
|
2023-04-30 16:32:28 +00:00
|
|
|
|
2020-11-17 11:16:34 +00:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|