I attempted to use the toLowerCase method for filtering words and domain names, but I keep receiving an empty array. I used the toLowerCase method to ensure that data containing capital letters or searched by capital letters are converted to lowercase. Below is my code:
var data = [ {
"name": "test",
"domain": "domain2",
"subdomain": "subdomain5",
"type": "yes"
},
{
"name": "test",
"domain": "domain2",
"subdomain": "subdomain6",
"type": "no"
},
{
"name": "hello",
"domain": "domain2",
"subdomain": "subdomain6",
"type": "no"
},
{
"name": "hello",
"domain": "domain2",
"subdomain": "subdomain6",
"type": "no",
"desc":"hello"
},
{
"name": "hello",
"domain": "domain5",
"subdomain": "subdomain6",
"type": "no",
"desc":"hello"
}
];
var namesearch = ["he"];
var domain = ["domain5","domain2"];
var result = data.filter((d)=>{
return (namesearch.length > 0 ? namesearch[0].toLowerCase().indexOf(d.name.toLowerCase()) > -1:'') && domain.length > 0 ? domain.includes(d.domain):''
});
console.log(JSON.stringify(result));