attr-accessor
This commit is contained in:
parent
2db3b98a85
commit
e0d2ed3bd0
26
src/attr-accessor.js
Normal file
26
src/attr-accessor.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* Получение свойства объекта
|
||||
* @param {object} src
|
||||
* @param {string} path
|
||||
*/
|
||||
function get(src, path) {
|
||||
path = path.split('.')
|
||||
for (let key of path) {
|
||||
src = src[key];
|
||||
if (src === undefined) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
return src;
|
||||
}
|
||||
|
||||
var fixture = {
|
||||
foo: {
|
||||
bar: [
|
||||
{qux: 'bingo'},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
// Проверка
|
||||
console.log(get(fixture, 'foo.bar.0.qux') === 'bingo');
|
Loading…
Reference in New Issue
Block a user