Files
30-seconds-of-code/snippets/select.md
Angelos Chalaris 0425ebefe7 Archive, multitagging, cleanup
Cleaned up the current snippets for consistency and minor problems, added multiple tags to most of them, archived a few.
2018-01-05 16:33:54 +02:00

366 B

select

Retrieve a property indicated by the selector from an object.

If the property does not exists returns undefined.

const select = (from, selector) =>
  selector.split('.').reduce((prev, cur) => prev && prev[cur], from);
const obj = { selector: { to: { val: 'val to select' } } };
select(obj, 'selector.to.val'); // 'val to select'