let obj = {x:5,y:6,z:7}; //объект
let arr = Object.keys(obj); //массив ключей
console.log(arr); //["x", "y", "z"]
function getNext() {
let key = arr.pop();
return { key: key, val: obj[key] };
}
console.log(getNext().val); //7
console.log(getNext().val); //6
console.log(getNext().val); //5
console.log(getNext().val); //undefined