Issue with forEach and indexOf and array

indexOf not working but the signsNames has ‘mj’ I try other ‘kyuukubu’ and other names sth makes that it not working
it logs ‘?’

signsMeshes.forEach(function(signMesh){


        var nodeName = signMesh.node.name;
    
        
        
        if(signsNames.indexOf("mj") > -1){
            signMesh.material = mat;

            console.log('applied mat');
        }
        else{
            console.log('?');
        }



    });

because the signsNames is dynamically created?

var signsNames = [];
    signs.forEach(function(s){
        mat = s.resource;
        signsNames.push(s.name);



    });

Can you post a small project for people to try to look at please?

it’s not possible because the signs are from the 3d model
but here is the array signsNames
["mat_mj_komatsu", "mat_mj_kitaike", "mat_mj_oomiya_y", "mat_mj_kuukoucyuuou_y_01", "mat_mj_kyuukabu_01", "mat_mj_kitaike_y", "mat_mj_yokohamakouen_y_02", "mat_mj_ueno", "mat_mj_shinjyuku_y", "mat_mj_shibuya", "mat_mj_toumei", "mat_mj_gouryuucyuui_y_02", "mat_mj_togoshi_y", "mat_mj_kuukoucyuuou_y_02", "mat_mj_shiodome", "mat_mj_ya_s", "mat_mj_deguchi", "mat_mj_shinjyuku", "mat_mj_gouryuucyuui_y_01", "mat_mj_kitaikebukuro_y", "mat_mj_honsen_y", "mat_mj_sen", "mat_mj_shinbashi", "mat_mj_ginza_y", "mat_mj_honsen", "mat_mj_shibuya_y", "mat_mj_deguchi_y", "mat_mj_wangansen_y", "mat_mj_dou", "mat_mj_mukoujima", "mat_mj_haneda_y", "mat_mj_wangan", "mat_mj_sokudocyuui_01", "mat_mj_hakozaki_y", "mat_mj_kawa", "mat_mj_cyuuou", "mat_mj_kousoku", "mat_mj_kyuukabu_02", "mat_mj_gouryuucyuui_01", "mat_mj_hakozaki", "mat_mj_sokudocyuui_02", "mat_mj_meguro_y", "mat_mj_togoshi", "mat_mj_ya_bunki", "mat_mj_gouryuucyuui_02", "mat_mj_meguro", "mat_mj_ueno_y", "mat_mj_yokohamakouen_y_01", "mat_mj_ginza", "mat_mj_kasumiga", "mat_mj_oomiya", "mat_mj_toumei_y", "mat_mj_haneda", "mat_mj_kousoku_y", "mat_mj_seki", "mat_mj_higashi", "mat_mj_kiba", "mat_mj_bukuro"]

the result of signsNames.push(s.name);

None of the strings in signsNames are ‘mj’ so this will always return -1. All of the strings contain ‘mj’ in the string but not just ‘mj’. The indexOf function is looking for an exact match.

1 Like

ok I confused the String.prototype.includes() with Array.prototype.includes()
in string not exact match
in array exact match

same with indexOf()

thanks