![[JS]递归对象或数组 [JS]递归对象或数组](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
function recursive(obj) {
var output = '';
if (typeof obj === 'object') {
for (var key in obj) {
var item = obj[key];
if (typeof item === 'object') {
output += recursive(item);
} else {
output += key + ':' + item + '\n';
}
}
} else {
output += obj + '\n';
}
return output;
}