I need to filter an Objects value to a new array && only have that value pass to the array if its key is found in an Array // I'm pretty sure there will be a way to do this, I'm just struggling to apply it to my current model.
The example below of what I've been trying to work
JSON file holds an array of objects -
I have filtered the selected object and stored its keys in a separate array (minus some I do not need):
let labelValues = () => {
// Filter the JSON data to remove not wanted
// This is explicit so will need to be written to be dynamic
// Data also is apearing out of context
return Object.keys(data[0]).filter((e)=>{
if(e == 'COMPANY' || e == 'HEADQUARTERS' || e == 'TOTAL'){
return false
}
return true
})
}
This leaves me with:
let X = ["JANUARY", "FEBUARY", "APRIL", "MARCH", "FEBUARY_1", "MAY"]
I now need to create a new array - by iterating over an object and only having the value pass to the array if, the objects KEY is in the above array X
Example of data structure of object:
let obj = {
APRIL: 35
COMPANY: "Walmart"
FEBUARY: 34
FEBUARY_1: 9
HEADQUARTERS: "Bentonville, AR"
JANUARY: 22.6
MARCH: 23.4
MAY: 21.1
TOTAL: 145.1
}
the desired array would be:
[35,34,9,22.6,23.4,21.1]
Thanks in advance - Wally