日期:2014-05-17 浏览次数:20386 次
function aa() { var OldArray = []; OldArray[0] = "a"; OldArray[1] = "1"; OldArray[2] = "5"; OldArray[3] = "3"; OldArray[4] = "b"; OldArray[5] = "6"; OldArray[6] = "2"; OldArray[7] = "a"; debugger; var NewArray = []; for (var i = 0; i < OldArray.length; i++) { if (!isNaN(OldArray[i])) { if (Number(OldArray[i]) > 3) { NewArray[Number(NewArray.length)] = OldArray[i]; } } } var str = ""; for (var i = 0; i < NewArray.length; i++) { str += ("-" + NewArray[i]) } alert(str); }
------解决方案--------------------
var OldArray =['a', 1, 5, 3, 'b', 6, 2, 7]; var NewArray = []; var pattern = /\d+/; for (var i in OldArray) { if (pattern.test(OldArray[i])) { if (OldArray[i] >3) { NewArray.push(OldArray[i]); } } }