var data = {
users: [
{
'user': 'barney',
'age': 36,
'active': true,
items:[
{a: 1, b: [{c: 1}, {c:2}]},
{a: 2, b: [{c: 3}, {c:4}]}
]
},
]
};
const path = 'items/a';
const path2 = 'items/b/c'
function test(p) {
const arr = p.split('/');
const key = arr.pop();
let value = data.users;
while(arr.length > 0) {
value = value.map(item => {
})
}
}
function getLanguageInfoByPath(data, path) {
const results= [];
let key = path;
if (path.includes('.')) {
key = key.split('.')[0];
} else if (path.includes('/')) {
key = key.split('/')[0];
}
if (path.includes('.')) {
results.push({
key: path.replace('.', '_'),
value: _.get(data, path)
});
} else if (path.includes('/')) {
const value = data[key];
const items = path.split('/').filter((item, index) => index > 0);
const last = items.pop();
value.map((item, index) => {
let temp = _.clone(items);
let array = item;
while(temp.length > 0) {
console.log(temp, 2)
const prop = temp.shift();
array[prop].map((ele) => {
console.log(temp)
if (temp.length ===0) {
console.log(ele, 'ele')
}
array = ele;
})
}
console.log(array, 'array', index)
})
const targetArray = [];
while (items.length > 0) {
const prop = items.shift();
value.map((item, index) => {
results.push({
key: '1',
value: item[prop],
})
})
}
} else {
results.push({
key,
value: data[key]
});
}
console.log('res', results)
}
console