判断每一个数是否在数组中,如果是,就不做任何操作,,如果不是,就添加进去...

            //判断每一个数是否在数组中
			var numArr = [1,2,3,4,5,6,7];
			var num = 8;
			var  flag = numArr.every(function(val,index){
				return val != num;
			})
			if(flag){
				numArr.push(num);
			}
			console.log(numArr);                                

转载于:https://www.cnblogs.com/freddyhuang/p/7526655.html