Skip to content
This repository was archived by the owner on Jan 31, 2024. It is now read-only.

Latest commit

 

History

History
43 lines (31 loc) · 716 Bytes

object_map.md

File metadata and controls

43 lines (31 loc) · 716 Bytes

objects/objectMap

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

Args

obj:object
The object to iterate over.

cb:function
The callback function.

Returns

An array with the mapped values.

Examples

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' ]