i have a big API answer with nested keys, that i don't want to add to my store as is. let's say i have an object
var apiResponse = {
... some fields
lines: [{
a: 'xxx',
b: 'xxx',
c: 'xxx',
d: 'xxx',
e: 'xxx'
}]
}
for now i am using
apiResponse.lines.map( ({a, b, e}) => ({a, b, e}) )
note there are more than 120 fields, and i may need to select more fields than i need today. so for code simplicity (or make it cleaner) i am trying to have an array lineFields
const neededFields = ['a', 'b' , 'e']
apiResponse.lines.map( ( { 'use my neededFieldsArray' } ) => ( { 'use my neededFieldsArray' }) ;
so when they day comes and i need to add fields , i just add in the neededFields array .
i used this approach with ODATA API before and it works like a charm because it accepts a string
var odataSelect= ['userName', 'Bio', 'ProfilePic']
var customUrl = `http://apiuri:someport/users?$select=${odataSelect.join(',')}`
i made a stackblitz template to test on. thank you