所以我有一个数组,var guests = [0,0,0,0,0,0];
现在,当我进入addRoomGuests时,我有一个开关,其中数组内的总数达到5,而我需要通过搜索案例5中的0项来从选择列表中删除项目.custet.indexOf(0但是,它起作用,它在前7个停止并且不会全部返回。
这是脚本:案例5需要返回所有客人[i] = 0,只是不确定如何。谢谢StackOverflow,你们摇滚!
var guests = [0,0,0,0,0,0];
function evaluateRoom(element, age, room){
switch(age){
case "adult":
age=0;
break;
case "kid":
age=1;
break;
}
room = room-1;
guests[age+room] = parseInt($(element).val());
console.log(guests);
addRoomGuests();
}
function addRoomGuests(){
var total = 0;
for(var i = 0; i < guests.length; i++){
total += guests[i];
}
console.log(total);
if(total){
switch(total){
case 5:
console.log('5 total, remove 1');
break;
case 6:
console.log('6 total, remove 2');
break;
case 7:
console.log('Max reached');
break;
}
}
}