const arr = [
{
title: '手机',
key: '0',
children: [
{ title: '苹果', key: '0-0' },
{ title: '小米', key: '0-1', children: [{ title: '12s', key: '0-1-0' }] },
],
},
{
title: '平板',
key: '1',
children: [
{ title: '华为', key: '1-0' },
{ title: '联想', key: '1-1', children: [{ title: 's8', key: '1-1-0' }] },
],
},
{
title: '耳机',
key: '2',
children: [
{
title: 'vivo',
key: '2-0',
},
],
},
]
let str = ''
const indexs = [0, 1, 0];
indexs.forEach((key, i) => {
if (i == 0) {
cur = arr[indexs[i]]
} else {
cur = cur['children'][indexs[i]]
}
str += (cur.title);
})
console.log(str)
console