add select

This commit is contained in:
musou1500
2017-12-19 19:59:07 +09:00
parent 9696089038
commit bc276d108a

15
snippets/select.md Normal file
View File

@ -0,0 +1,15 @@
### select
Retrieve a property that indicated by the selector from object.
If property not exists returns `undefined`.
```js
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'
```