[{name:'北京'},{city:'西安'}],
[{name:'上海'},{city:'包头'}],
[{name:'广州'},{city:'福州'}],
[{name:'北京'},{city:'广州'}],
[{name:'广州'},{city:'太原'}],
[{name:'上海'},{city:'昆明'}]
]
var result = []
for(var i = 0i<college.lengthi++){
var ci = college[i], obj = ci[0]
var isExisted = false
for(var j =0j<result.lengthj++){
var rj = result[j]
if(rj.type==obj.name){
rj.push(ci)
isExisted = true
break
}
}
if(!isExisted){
var tmp = [ci]
tmp.type = obj.name
result.push(tmp)
}
}
college = result
console.log(college)
<script type="text/javascript">//你的代码
var myarr = [['小A','女',21,'大一'],['小B','男',23,'大三'],['小C','男',24,'大四'],['小D','女',21,'大一'],
['小E','女',22,'大四'],['小F','男',21,'大一'],['小G','女',22,'大二'],['小H','女',20,'大三'],
['小I','女',20,'大一'],['小J','男',20,'大三']]
var firarry = new Array()
for(var i=0i<10++i){ //这句不对,i=0,++1,那么下面这行的i就是1了
if(myarr[i][3]=='大一'){
firarry = myarr[i]
//document.write(firarry)//这行输出大一的,没有用
}
}
for(var j=0j<4++j){//因为上面的被覆盖了,所以这是最后一个大一的,再遍历也只有一个人,
// 而且控制条件写的不对,怎么可以小于4呢,里面只有一个人呀!
if(firarry[j][1]=='女')
document.write(firarry[j][0])
}
/* 这里附上我写的一个运行成功的代码
var myarr=[['小A','女',21,'大一'],['小B','男',22,'大三'],['小c','男',15,'女'],['小D','女',14,'大一']]
for(var i=0i<myarr.lengthi++){
if(myarr[i][3]=='大一'&&myarr[i][1]=='女'){
document.write(myarr[i])
}
}
*/
</script>
给你个提示吧,你可以随机出位置,然后就行了例子:StrRand = ""int i,j
Random random = new Random(DateTime.Now.Millisecond)
i = random.Next(a[0].length)j = random.Next(a[0][0].length)最终的得出的随机数a[i][j]