首页 > 编程语言 > 正文

js 三维数组,请问js中如何定义一个三维数组,不用循环,最原始的方法就行了

2020-04-18 10:07:53  来源:http://www.yummyboobs.net  编辑:admin

javascript怎么实现三维数组

不就是一个省,市,区三级联动么,你这里才到第二级,怎么就用到三级了 <html><head> <title>下拉列表与图片</title> <script type="text/javascript" language="javascript"> var province = ['河北省', '河南省', '湖北省', '湖南省']; province['河北省'] = ['石家庄', '保定', '廊坊', '张家口', '承德', '唐山', '邯郸']; province['河南省'] = ['郑州', '开封', '洛阳', '平顶山', '许昌', '周口', '川汇']; province['湖北省'] = ['武汉', '黄石', '荆州', '天门7a6431333264623263', '潜江', '随州', '仙桃']; province['湖南省'] = ['长沙', '湘潭', '湘乡', '衡阳', '耒阳', '岳阳', '临湘']; province['河北省']['邯郸'] = ['峰峰矿区', '彭城']; function showpro(value) { var city = document.getElementById("city"); city.options.length = 0; for (var i = 0; i < province[value].length; i++) { var opt = document.createElement("OPTION"); opt.text = province[value][i]; opt.value = province[value][i]; city.options.add(opt); } } function showan(value) { var an = document.getElementById("an"); var pro = document.getElementById("province").value; an.options.length = 0; for (var i = 0; i < province[pro][value].length; i++) { var opt = document.createElement("OPTION"); opt.text = province[pro][value][i]; opt.value = province[pro][value][i]; an.options.add(opt); } } </script></head><body> <select onchange="showpro(this.value)" id="province"> <option value="河北省">河北省</option> <option value="河南省">河南省</option> <option value="湖北省">湖北省</option> <option value="湖南省">湖南省</option> </select> <select onchange="showan(this.value)" id="city"> </select> <select id="an"> </select></body></html>

js三维数组的遍历问题

vararr=[];for(vari=0;i<3;i++){专arr[i]=[];for(varj=0;j<i+1;j++){arr[i][j]=[];for(varz=0;z<3;z++){varv='';if(z==0){k='A';v='abc';}elseif(z==1){k='B';v='2017';}elseif(z==2){k='C';v='aa';}arr[i][j][k]=v;};};};console.log(arr);望采纳,属不懂请追问

如何使用三维数组存储这首诗,并通过foreach语句输出。求C#代码

String[][][] test = { new String[][] { new String[] { "床前明月光" } }, new String[][] { new String[] { "疑是地e799bee5baa6e79fa5e98193e59b9ee7ad9431333337613262上霜" } }, new String[][] { new String[] { "举头望明月" } }, new String[][] { new String[] { "低头思故乡" } }, }; foreach (var item in test) { foreach (var item1 in item) { foreach (var item2 in item1) { Console.WriteLine(item2); } } } Console.ReadKey();

求教!js二维数组中,如何把具有相同种类name的值筛选出来,组成三维数组

varcollege=[[{name:'北京'},{city:'西安'}],[{name:'上海'},{city:'包头'}],[{name:'广州'},{city:'福州'}],[{name:'北京'},{city:'广州'}],[{name:'广州'},{city:'太原'}],[{name:'上海'},{city:'昆明7a686964616fe58685e5aeb931333363376366'}]];varresult=[];for(vari=0;i<college.length;i++){varci=college[i],obj=ci[0];varisExisted=false;for(varj=0;j<result.length;j++){varrj=result[j];if(rj.type==obj.name){rj.push(ci);isExisted=true;break;}}if(!isExisted){vartmp=[ci];tmp.type=obj.name;result.push(tmp);}}college=result;console.log(college);

js中字符串如何转三维数组

参考答案:勿以恶小而为之,勿以善小而不为。(刘备)