var a1=[
{name:'1'},
{name:'2'},
{name:'3'}
];
var a2=[
{name:'1'},
{name:'2'},
{name:'4'},
{name:'5'}
]
我想用for循环,把{name:'3'},{name:'4'},{name:'5'}拿出来,怎么拿?
网页链接
第1个回答 2018-03-17
var a1=[
{name:'1'},
{name:'2'},
{name:'3'}
];
var a2=[
{name:'1'},
{name:'2'},
{name:'4'},
{name:'5'}
]
for (i = 0; i < a1.length; i++) {
if (a1[i].name === '3' || a1[i].name === '4', a1[i].name === '5') {
alert(a1[i])
}
}追问
{name:'1'},
{name:'2'},
{name:'3'}
];
var a2=[
{name:'1'},
{name:'2'},
{name:'4'},
{name:'5'}
]
for (i = 0; i < a1.length; i++) {
if (a1[i].name === '3' || a1[i].name === '4', a1[i].name === '5') {
alert(a1[i])
}
}追问
这只是一个例子,问题是两个数组对比。。。。
第2个回答 2018-03-17
function cmpare() {
for (var i = 0; i < arguments.length; i++) { return arguments[i].toString() == arguments[i + 1] ? true : false;
}
}12345
var a = [1,2];
var b = [1,3];
console.log(cmpare(a, b));追问
for (var i = 0; i < arguments.length; i++) { return arguments[i].toString() == arguments[i + 1] ? true : false;
}
}12345
var a = [1,2];
var b = [1,3];
console.log(cmpare(a, b));追问
不对啊。我想把{name:'3'},{name:'4'},{name:'5'}放在一个数组里,不是返回true
本回答被网友采纳