I have an array of objects that I need to turn into a new single object.
This is structure of array:
class QueryFilter {
filterName;
filterValue;
}
let filter1 = new QueryFilter();
filter1.filterName = "SpamScore";
filter1.filterValue = 5;
let filter2 = new QueryFilter();
filter2.filterName = "Pages";
filter2.filterValue = 50;
let filters = [filter1, filter2];
I need to turn filters into an object like this:
let newObj = {
SpamScore: 5,
Pages: 50
};
I have been trying with map and assign but I cant figure out the way I am supposed to do this. Does this require reflection of some type or is there a simple way?
for(let filter of filters) { newObj[filter.filterName] = filter.filterValue }object.propertylet newObj = {}; for(let f of filters) { newObj[f.filterName] = f.filterValue }