This specific function serves to convert a list into an array:
const myList = {"value":10,"rest":{"value":20,"rest":null}};
function convertListToArray(list) {
let arr = [];
for (const prop in list) {
if (prop == "value") {
arr.push(prop);
} else if (prop == "rest") {
for (const innerProp in rest) {
arr.push(innerProp);
}
}
}
}
console.log(JSON.stringify(convertListToArray(myList)));
However, encountering the error
Uncaught ReferenceError ReferenceError: rest is not defined
What is the best way to iterate through the rest object? Or can you propose an alternative approach to rewrite this function?