【优极限】 HTML+CSS+JavaScript+jQuery前端必学教程,小白教学,前端基础全套完成版_哔哩哔哩_bilibili<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>类型转换</title>
</head>
<body>
<script type="text/javascript">
console.log("==========");
console.log(1=='1');
console.log(1==='1');
var arr1 = [];
console.log(arr1);
var arr2 =[1,2,'a',true];
console.log(arr2);
var arr3 = new Array(1,2,3);
console.log(arr3);
var arr4 = new Array(5);
console.log(arr4);
console.log("==========");
console.log(arr2[1]);
console.log(arr2[10]);
arr2[1]=20;
console.log(arr2);
arr2[10] = 100;
console.log(arr3.lenght);
arr3.length = 5;
console.log(arr3);
arr3.name = "zhangsan";
console.log(arr3);
arr3["pwd"]="123456";
console.log(arr3);
console.log(arr3["name"]);
console.log("==========");
console.log(arr3);
console.log("for遍历循环");
for(var i =0; i<arr3.length;i++) {
console.log("下标:" +i+ "值:"+arr3[i] );
}
console.log("---for...in----");
for (var i in arr3){
console.log("下标:" +i+ "值:"+arr3[1]);
}
console.log("---forEach----")
arr3.forEach(function(element,index){
console.log("下标:" +index+"值:"+element);
})
console.log("==========");
var arr5 =["a","b","c"];
arr5[arr5.length]="d";
arr5.push("e")
console.log(arr5);
console.log(arr5.indexOf("a"));
console.log(arr5.indexOf("t"));
console.log(arr5.join("-"));
var str = "1,2,3,4,5";
console.log(str.split(","));
function fn01(a,b){
console.log(a+b);
}
console.log(fn01);
var fn02 =function(a,b){
console.log(a+b);
}
var fn03 = new Function("a","b","return (a+b)");
function fn04(a,b){
return (a+b);
}
</script>
</body>
</html>