I've got an array with nested objects in it. Something like this:
const results = [
{
general: {
orderID: '5567',
created: 1548765626101,
status: 'new'
},
company: {
companyName: 'company x',
companyEmail: '[email protected]',
companyContact: 'John Doe'
},
customer: {
customerName: 'Jane Doe',
customerEmail: '[email protected]'
},
products: [
{
productID: 4765756,
productName: 'Product x',
productDescription: 'Description for product x'
},
{
productID: 4767839,
productName: 'Product y',
productDescription: 'Description for product y'
}
],
payment: {
price: 1000,
method: 'cash'
}
},
]
(To keep it a little bit structured I only inserted one result object for this question. But let's say there are 100 elements in the results array.)
A user is able to type in a search term and check/uncheck keys that will include or exclude these keys. The keys are hardcoded in a list.
So for example. A user types in 'jane' and checks customerName and customerEmail as the wanted keys to search. Or a user types in 'x' and checks productName.
How can I dynamically search into these checked keys? I'm already having the selected keys in an array.
So for the first example, I've got ['customerName', 'customerEmail'].
For the second one it's ['productName']
I have used array.filter() before for hardcoded keys but I have no clue on how to filter for these dynamic keys.
Can someone help me out with a breakdown of the different steps? I'm working with es6, without external libraries.