I want to pass a function an array of keys and an object, and return a new object that only contains the key/value pairs that I specify in the keys array.
So if I had an object like this:
{"name" : "John Smith", "position" : "CEO", "year" : "2019" }
And I passed the array
["name", "year"]
the new object returned would be:
{"name" : "John Smith", "year" : "2019" }
I've been playing around with it, but my code is not working.
function parse(keys, data) {
let obj = JSON.parse(data);
let newObj = {};
keys.array.forEach(element => {
newObj[element] = obj.element;
});
return newObj;
};