Title: var arr = [' 100px ', ' abc '-6, [], -98765, $,-2, 0, ' + ',, function () {alert (1);}, null, document, [], True, ' 200px '- 30, ' 23.45 ', 5, Number (' abc '), function () {alert (3);}, ' XYZ '-90];
1. Find all the numbers in arr:-98765, 34,-2, 0, 5
2, find can be converted into numbers: ' 100px ',-98765, 34,-2, 0, ' 300 ', ' 23.45 yuan, 5
3, after turning into a number, the maximum value is judged out: 300
4. Find out where NaN is located: 1 14 17 1
For:
1.
function fn1 () { for (var i=0;i<arr.length;i++) { if(typeof Arr[i] = = = ' Number ' && arr[i] = = = Arr[i]) { //-98765, 34,-2, 0, 5
} }}fn1 ();
2.3.
varARR2 = [];functionfn1 () { for(vari=0;i<arr.length;i++){ if(!IsNaN (parseint (arr[i))) {Arr2.push (arr[i]);//is numeric: 100px,-98765, 34,-2, 0, 300, 23.45 yuan, 5}}}fn1 ();varTMP =arr2;varmax = Tmp[0]; for(vari = 1;i < tmp.length;i++){ if(Max <Tmp[i]) {Max=Tmp[i]; }}alert (max);
4.
var arr3 = []; function fn1 () { for (var i=0;i<arr.length;i++) { if( typeof Arr[i] = = ' number ' && isNaN (number (Arr[i]))) { Arr3.push (i) ; }}} FN1 (); alert (ARR3);
The judgment value and array value of Javascript arrays