В вашем операторе if, if (def.key in item)
, он проверит, равно ли значение def.key
имени атрибута в элементе. Чтобы выполнить то, о чем вы думали, посмотрите комментарии в коде ниже:
// set of keys
const defConfigs = [{title: "Id", key: "id"},
{title: "Tenant", key: "tenant"},
{title: "Opened", key: "opened"},
{title: "Title", key: "title"},
{title: "Status", key: "status"},
{title: "Priority", key: "priority"}];
// items as array of objects
const items = [{id: "INC000000004519", title: "Follow-up after INC000000004507", description: null, urgency: "4-Low", severity: "4-Minor/Localized"},
{id: "INC000000004515", title: "network drop:↵Network Element CVU042_Johnstown get unsynchronized↵Network Element CVU043_Redman", description: "Client network drop since 08:51 until 09:06, pleas…ork Element CVU045_North_Salem get unsynchronized", urgency: "3-Medium", severity: "3-Moderate/Limited"},
{id: "INC000000004088", title: "not able to schedule GPEH in ABC", description: "Contact: abc@xyz.com↵+14692669295↵…WCDMA, we are not able to schedule GPEH in ABC. I", urgency: "4-Low", severity: "4-Minor/Localized"},
{id: "INC000000004512", title: "SR Updated - P3 - 2018-0427-0305 - xyz TELECOMMUNICATIONS ROMANIA S.R.L - Lost the mng connect", description: null, urgency: "4-Low", severity: "4-Minor/Localized"},
{id: "INC000000004414", title: "Acme incident 1 title", description: "Acme incident 1 description", urgency: "2-High", severity: "1-Extensive/Widespread"}];
// trying to search for string in keys defined in defConfigs
items.filter(item =>
defConfigs.forEach((def) => {
//iterate through all attributes in the object
for(var key in item){
//check if the attribute exists, if it has the method 'indexOf' (if it's a string), and that it has def.key in the string
if (item[key] && item[key].indexOf && item[key].indexOf(def.key)!= -1) {
//match only accepts regular expressions which are signified in JS by enclosing the expression with forward slashes
return (item[def.key].toString().toLowerCase().match(/low/).length >1);
}
}
}));