const sampleObj = {
apple: 1,
orange: 2
};
let newFunction = (...objects) => {
console.log(apple,orange); // ReferenceError: apple is not defined
};
newFunction(sampleObj);
I am looking to access the object properties directly within the function without using sampleObj.apple
or sampleObj.orange
.
Note: I am aware that I can manually define the arguments ({ apple, orange }
), but I prefer not to do so as the object may have an unknown or variable number of properties.