Filter array based on other search array

how to filter with signsNames array the filtered array? so I have the 38 meshes

var signsNames = 
    ["mj_oomiya_y",
     "mj_kuukoucyuuou_y_01",
     "mj_kyuukabu_01",
     "mj_kitaike_y",
     "mj_yokohamakouen_y_02",
     "mj_ueno",
     "mj_shinjyuku_y",
     "mj_shibuya",
     "mj_toumei",
     "mj_gouryuucyuui_y_02",
     "mj_togoshi_y",
     "mj_kuukoucyuuou_y_02",
     "mj_shiodome",
     "mj_ya_s",
     "mj_deguchi",
     "mj_shinjyuku",
     "mj_gouryuucyuui_y_01",
     "mj_kitaikebukuro_y",
     "mj_honsen_y",
     "mj_sen",
     "mj_shinbashi",
     "mj_ginza_y",
     "mj_honsen",
     "mj_shibuya_y",
     "mj_deguchi_y",
     "mj_wangansen_y",
     "mj_dou",
     "mj_mukoujima",
     "mj_haneda_y",
     "mj_wangan",
     "mj_sokudocyuui_01",
     "mj_hakozaki_y",
     "mj_kawa",
     "mj_cyuuou",
     "mj_kousoku",
     "mj_meguro_y",
     "mj_ya_bunki",
     "mj_ueno_y"];

var regex = /Default/g;

var filtered =  this.meshes.filter(function(mesh){
        var matName = mesh.material.name;


        var matching = matName.match(regex);

        return matching;

    });

var test = filtered.filter(function(mesh){
        return signsNames.includes(mesh);
  
    });

the equivalent of manually doing if(sth === name){
}
else if (sth === name2){}

Hi @grzesiekmq,

If you mean how to find the index of an array item based on its name, something like this:

var itemIndex = signsNames.indexOf(name);
if( itemIndex > -1){
   // item found
} 

sth like this but not working
the element of array as parameter in .includes

signsNames.forEach(function(name){
        n = name;
    });


 var filSigns = signsMeshes.filter(function(mesh){

        return mesh.node.name.includes(n);
    });

If you mean replacing the ES6 filter method with an ES5 equivalent, then use a regular loop and indexOf:

var filteredList = [];

signsNames.forEach( function(name){
    if( mesh.node.name.indexOf(name) > -1 ){
        filteredList.push(name);
    }
});
1 Like

hmm I mean sth like this
mesh.node.name.includes("mj_oomiya_y");

mesh.node.name.includes("mj_kuukoucyuuou_y_01");

but as parameter how to pass item from array to .includes?

so
mesh.node.name.includes(param);

In the code I posted above param is name, so it’s passed each time to indexOf > -1. Which does the same check as the includes method you mention.

Unless you are trying to do something different, and I don’t get you here :slight_smile: