Value of array judgment

Source: Internet
Author: User

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "Text/html;charset=utf-8" >
<title>Document</title>
<style>
/*CSS Reset Start */
body,h1,h2,h3,h4,h5,h6,p,dl,dd,ul,ol,pre,form,input,textarea,th,td,select{margin:0;padding:0;font-size:14px; font-family: "Microsoft Yahei";}
Input{width:300px;height:20px;vertical-align:middle;}
Li{list-style:none;vertical-align:top;}
A{text-decoration:none;}
Img{border:none;vertical-align:top;}
Table{border-collapse:collapse;}
Textarea{resize:none;overflow:auto;}
body{margin-top:10px;}
/*CSS Reset End */
form{width:300px;}
fieldset{margin:20px;border:2px dashed palevioletred;}
</style>
<script>
Window.onload = function () {
var arr = [' 100px ', ' abc '-6, [], -98765, $,-2, 0, ' + ',, function () {alert (1);}, null, document, [], True, ' 200px '-30, ' 23.45 Yuan ', 5, Number (' abc '), function () {alert (3);}, ' XYZ '-90];


var oallnum = document.getElementById (' Allnum ');
var onum = document.getElementById (' Num ');
var omaxnum = document.getElementById (' Maxnum ');
var onanlocation = document.getElementById (' nanlocation ');
var arr1 = [];
var arr2 = [];
var arr3 = [];


/ /1. All the numbers in the array: ↓↓
for (Var i=0;i<arr.length;i++) {
if (typeof arr[i] = = ' number ' && arr[i] = = = Arr[i]) {
Arr1.push (Arr[i]);
}
}
Oallnum.value = arr1;


// 2. The array can be converted into numbers: ↓↓


for (Var i=0;i<arr.length;i++) {
if (IsNaN (parseint (arr[i)) = = False) {
Arr2.push (Arr[i]);
}
}
Onum.value = arr2;


// 3. Can be converted to a number and then take the maximum value: ↓↓
var tmp =arr2;


var max = tmp[0];


for (Var i=1;i<tmp.length;i++) {


if (Max<tmp[i])
{
Max=tmp[i];
}


}
Omaxnum.value=max;




//4.NAN location: ↓↓
for (Var i=0;i<arr.length;i++) {
if (typeof arr[i] = = ' number ' && IsNaN (number (arr[i))) {
Arr3.push (i);
}
}
Onanlocation.value = ARR3;
}
</script>
<body>
<form action= "" >
<fieldset>
<legend> Output Results </legend>
All numbers in arr array: <input type= "text" id= "Allnum"/><br/><br/>
The ARR array can be converted into numbers: <input type= "text" id= "Num"/><br/><br/>
After turning into a number, take the maximum value: <input type= "text" id= "Maxnum"/><br/><br/>
Nan Location: <input type= "text" id= "Nanlocation"/>
</fieldset>
</form>
</body>

Value of array judgment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.