The topics are as follows:
var arr = [' 100px ', ' abc ' -6,[],-98765,34,-2,0, ' + ',,functionnulltrue function() {alert (3);}, ' xyz ' -90 ]; // 1. Find all the numbers in arr: -98765,,-2, 0, 5 // 2, find can be converted into numbers: "100px",-98765, 34,-2, "300", "23.45 Yuan", 5 // 3, the conversion into a number, the maximum value to be judged out: // 4. Find out where Nan is located: 1, +, +
1. Find all the numbers in arr:-98765, 34,-2, 0, 5
// 1. Find all the numbers in arr: -98765,,-2, 0, 5 var num1 =[]; for (var i = 0;i<arr.length; i++) { // filter out numbers and strings that can be converted to numbers var re = /^(\-?) \d+$/; if typeof (Arr[i])! = ' String ') { num1.push (arr[i]);} } Console.log (NUM1);
2, find can be converted into numbers: "100px",-98765, 34,-2, "300", "23.45 Yuan", 5
// 2, find can be converted into numbers: "100px",-98765, 34,-2, "300", "23.45 Yuan", 5 var num2=[]; for (var j =0; j<arr.length; J + +) { //parseint parses a string and returns an integer if (parseint (Arr[j])) { Num2.push (arr[j]);} } Console.log (num2);
3, the conversion into a number, the maximum value judged out: 300
// 3, the conversion into a number, the maximum value to be judged out: // assuming the maximum value is the first element of the array, the loop ratio var _max = num2[0]; for (var m=0; m<num2.length; m++) { if(_max < num2[m]) { = NUM2[M]; } } Console.log (_max);
4. Find out where Nan is located: 1, 14, 17, 19
// 4. Find out where Nan is located: 1, +, + var _index = []; for (var n=0; n<arr.length; n++) { if(Number.isnan (Arr[n])) { _index.push (n) ; }} Console.log (_index);
Check the data to complete, do not forget the fast AH
Thoughts: "Warm and know New", has been remembered ~
A JavaScript array operation problem