I want to filter data using spread operator. I have a function that has category as its argument.
The problem is when I pass category as arg to the spread operator I got an obvious error:
The symbol "category" has already been declared.
How can I use category instead of the hardcoded "Headlines"?
const data = {
"subscription": {
"Headlines": ["headline1", "headline1"],
"News": ["news1"],
}
}
const category = "Headlines";
// const { category, ...rest } = data.subscription; This does not work.
const { Headlines, ...rest } = data.subscription; // This works.
const updatedData = {...data, subscription: rest};
console.log(updatedData);