1.学习资料
【优极限】 HTML+CSS+JavaScript+jQuery前端必学教程,小白教学,前端基础全套完成版_哔哩哔哩_bilibili
2.
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(arr2);
2.1
console.log(arr3.length);
//设置数组的长度
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);
2.2
console.log("---for循环遍历---");
//for循环遍历
for(var i=0;i<arr3.length;i++) {
console.log("索引:" + i + ",值:"+arr3[i]);
}
//for...in
console.log("---for...in---");
for(var i in arr3) {
console.log("下标:"+i+",值:"+arr3[i]);
}
//forEach
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.indexOf("a"));
console.log(arr5.indexOf("t"));
console.log(arr5.join("-"));
var str="1,2,3,4,5";
console.log(str.split(","));
2.3
function fn01(a,b) {
console.log(a+b);
}
console.log(fn01);
var fn02=function(a,b) {
console.log(a+b);
}
console.log(fn02);
var fn03=new Function('a','b','return (a+b);');
console.log(fn03);
function fn04(a,b) {
return (a+b);
}
2.4
console.log("==========");
function test01(x,y) {
console.log(x+y);
}
test01();
test01(1);
test01(1,2);
function test02(x,x) {
console.log(x);
}
test02(1,2);
function test03(x) {
x=x||"x";
console.log(x);
}
test03(10);
test03();
function test04(x) {
(x==null&&x!=undefined)?x=x:x="x";
console.log(x);
}
test04();
test04("Hello");
var num=10;
function test05(num) {
num=20;
}
test05(num);
console.log(num);
var obj={name:"zhangsan"};
console.log(obj);
function test06(o) {
o.name="lisi";
}
test06(obj);
console.log(obj);
2.5
console.log("===========");
function f1() {
console.log("常用调用模式...");
}
f1();
var f2=function(a) {
console.log("函数调用模式...");
return a;
}
var num1=f2(1);
console.log(num1);
var obj={
name:"zhangsan",
age:18,
sex:true,
cats:["小红","小李"],
dog:{
name:"旺旺",
age:1
},
sayHello:function() {
console.log("你好");
}
}
console.log(obj);
console.log(obj.dog);
console.log(obj.sayHello);
obj.sayHello();
console.log("==========");
function a1() {
console.log("没有返回值...");
return;
console.log('..........');
}
console.log(a1());
function a2() {
console.log("有返回值...");
return "test";
}
console.log(a2());
console.log("==========");
var pp="Hello";
function qq() {
var box=10;
box2=20;
}
qq();
console.log(qq);
console.log(box);
console.log(box2);