Trying to figure out how to use a variable as a key name inside a filter function.
Example array of objects:
const data = [{"itemID": 11, "Complete": true, "Started": true},{"itemID": 16, "Complete": false, "Started": false}];
Conditional statement:
if(isStartMode){
const currentMode = 'Started'
} else {
const currentMode = 'Complete'
}
Variable
var possible_ItemID = 16;
Filter function
const lineItem = data.filter((item) => item.itemID === possible_ItemID && item.{currentMode} !== true)
console.log(lineItem)
I'm looking for a way to switch either "Started" or "Complete" where it says {currentMode}, without having to make separate hardcoded statements for each: item.Started or item.Complete
There's just something I'm missing in the syntax...