И сам отвечу:
https://stackoverflow.com/questions/47062922/how-t...
UPD: Допиленный вариант:
https://jsfiddle.net/yarkov_aleksei/dvp7k9h6/const data = {
param: 'value',
key: {
nested: {
double_nested: 'value'
}
},
nested: {
array: ['key 1', 'key 2']
}
}
function getObjectKeys(obj, prefix = '') {
const keys = Object.keys(obj).reduce((res, el) => {
if (Array.isArray(obj[el])) {
return [...res, ...obj[el].map((item, i) => `${prefix}${el}[${i}]`)]
} else if (obj[el] !== null && typeof obj[el] === 'object') {
return [...res, ...getObjectKeys(obj[el], prefix + el + '.')]
} else {
return [...res, prefix + el]
}
}, [])
keys.sort()
return keys
}
const array = getObjectKeys(data)
console.log(array)