# 数组循环匹配的问题

• 69

``let code = ["110000", "110101"]``
``````let lvOne = [110100, 310100, 440100, 440300, 330100, 320100, 320500, 330200, 510100, 420100, 500100, 350200]
let lvTwo = [120000, 370100, 131000, 370200, 210200, 430200, 230100, 210100, 610100, 220100, 430100, 350100, 410100, 130100, 440600, 441900, 320200, 370600, 140100, 340100, 360100, 450100, 530100, 330300, 370300, 130200, 650100, 520100, 460100, 620100, 640100, 630100, 150100, 350500, 150200, 320600, 230600, 320300, 370700, 320400, 330600, 370800, 320900, 371300, 410300, 370500, 321000, 331000, 330400, 130900, 321200, 321100, 330700, 130600, 220200, 210300, 370900, 420500, 442000, 441300, 371000, 371400, 371500, 430700, 350600, 371600, 440900, 320800, 440700, 340200, 440800, 450200, 440400, 510700, 520300, 371700]``````
``````let arr = code.split(',');
let {LevelOneCities,LevelTwoCities} = LvCities;
let toLevelCity = null;``````

##### 1个回答
✓ 已被采纳

``````var toLevelCity = [];
if(code.some(v=>lvOne.includes(+v))) toLevelCity.push('lvOne');
if(code.some(v=>lvTwo.includes(+v))) toLevelCity.push('lvOne');
if(toLevelCity.length == 0) toLevelCity.push('other');``````