数组之判断取值
来源:互联网 发布:java switch 改 if 编辑:程序博客网 时间:2024/04/30 04:40
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
<style>
/*css reset开始*/
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结束*/
form{width: 300px;}
fieldset{margin: 20px;border: 2px dashed palevioletred;}
</style>
<script>
window.onload = function(){
var arr = ['100px', 'abc'-6, [], -98765, 34, -2, 0, '300', , function(){alert(1);}, null, document, [], true, '200px'-30,'23.45元', 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.数组里所有的数字:↓↓
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.数组里可以转成数字的:↓↓
for(var i=0;i<arr.length;i++){
if(isNaN(parseInt(arr[i])) == false){
arr2.push(arr[i]);
}
}
oNum.value = arr2;
// 3.可以转成数字的再从中取最大值:↓↓
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所在的位置:↓↓
for(var i=0;i<arr.length;i++){
if(typeof arr[i] == 'number' && isNaN(Number(arr[i]))){
arr3.push(i);
}
}
oNanLocation.value = arr3;
}
</script>
</head>
<body>
<form action="">
<fieldset>
<legend>输出结果</legend>
arr数组里所有的数字:<input type="text" id="allNum"/><br/><br/>
arr数组里可以转成数字的: <input type="text" id="Num"/><br/><br/>
把转成数字以后的,再取最大值:<input type="text" id="maxNum"/><br/><br/>
NaN所在的位置:<input type="text" id="nanLocation"/>
</fieldset>
</form>
</body>
</html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
<style>
/*css reset开始*/
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结束*/
form{width: 300px;}
fieldset{margin: 20px;border: 2px dashed palevioletred;}
</style>
<script>
window.onload = function(){
var arr = ['100px', 'abc'-6, [], -98765, 34, -2, 0, '300', , function(){alert(1);}, null, document, [], true, '200px'-30,'23.45元', 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.数组里所有的数字:↓↓
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.数组里可以转成数字的:↓↓
for(var i=0;i<arr.length;i++){
if(isNaN(parseInt(arr[i])) == false){
arr2.push(arr[i]);
}
}
oNum.value = arr2;
// 3.可以转成数字的再从中取最大值:↓↓
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所在的位置:↓↓
for(var i=0;i<arr.length;i++){
if(typeof arr[i] == 'number' && isNaN(Number(arr[i]))){
arr3.push(i);
}
}
oNanLocation.value = arr3;
}
</script>
</head>
<body>
<form action="">
<fieldset>
<legend>输出结果</legend>
arr数组里所有的数字:<input type="text" id="allNum"/><br/><br/>
arr数组里可以转成数字的: <input type="text" id="Num"/><br/><br/>
把转成数字以后的,再取最大值:<input type="text" id="maxNum"/><br/><br/>
NaN所在的位置:<input type="text" id="nanLocation"/>
</fieldset>
</form>
</body>
</html>
0 0
- 数组之判断取值
- 数组算法取值
- 二维数组取值
- javascript数组取值
- 多维数组取值
- JQuery判断DropDownList 取值
- string分割成数组,且ListBox根据数组添加item,且对应ListBox取值判断及数组循环
- 对象数组 取值 (双循环取
- 判断数组中包含重复数(大数中取重复)
- js 判断元素在数组中和取反操作
- js json数组取值
- json 数组对象 取值
- js相关1.设置下拉框只读2.判断两个数组是否相等3.form表单取值
- JavaScript 判断checkbox取值问题
- radio后台取值的判断
- struts2标签判断session的取值
- 工具函数之取数组中的最值和最优值
- 算法小记之01--数组中取三个数等于定值
- Java开发日志分析工具Log4j使用详解
- Java----再学习-----Java基本运算符
- 软件架构————需求分析核对表
- GNU-makefle (二) Makefile 文件名,include,make工作方式
- Construct Binary Tree from Inorder and Postorder Traversal (leetcode)
- 数组之判断取值
- 云计算设计模式(十九)——运行重构模式
- opencv中在图片上显示文本
- IE下GridView导出Excel无反应
- 如何用SPSS对数据进行标准化处理?
- 百个前端设计常用Javascript语句
- Apple LLVM 6.0 Error
- C++ HTTP协议 下载文件
- select函数详细用法解析