For example, I have
const eva = {name: "Eva", age: 3, hobby: "dance", state: "NY"};
const ann = {name: "Ann", age: 9, hobby: "read", state: "WA", schoolyear: 3};
I want to have a trim function, which only keeps the fields I want.
const fields = ["name", "age", "state"]
and the output will be
const eva2 = {name: "Eva", age: 3, state: "NY"};
const ann2 = {name: "Ann", age: 9, state: "WA"};
I can't iterate through all fields and delete fields inside the loop. That will end the loop earlier.
Thanks!