Creates an array from the results of calling a function on each item in an object.
Does not add undefined values to the resulting array.
function objectMap(obj: object, cb: function): array
obj:object
The object to iterate over.
cb:function
The callback function.
An array with the mapped values.
import { objectMap } from '@deskpro/js-utils/dist/objects';
const values = {
name: 'item',
title: 'foo',
alt: 'bar'
};
let results = objectMap(values, (val, key) => {
if (key !== 'alt') {
return val.toUpperCase();
}
});
console.log(results);
// Outputs:
// [ 'ITEM', 'FOO' ]