I'd like to filter and restructure some specific data, but I'm having some trouble getting it to produce the proper structure.
I have this data response in this structure....
var response = {
badProperty1: "bad property text"
goodProperty1: "abc"
goodProperty2: "bcd"
goodProperty3: "cde"
goodProperty4: "def"
goodProperty5: "efg"
badProperty2: "fgh"
};
I'd like to convert my response object into an array like this structure exactly...
var newFilteredStructuredArray = [
{goodProperty1: 'abc'},
{goodProperty2: 'bcd'},
{goodProperty3: 'cde'},
{goodProperty4: 'def'},
{goodProperty5: 'fgh'}
];
However I'd like to filter out the bad properties before I get my new array. I'd like my array to only include these specific property names and filter everything else that I started with.
var possiblePropertyNames = ['goodProperty1', 'goodProperty2', 'goodProperty3', 'goodProperty4', 'goodProperty5'];
possiblePropertyNamesand use its elements to produce the expected output.Array.prototype.map()might be useful.