js中{} [] 详解 {}中代表一个对象 [] 中代表一个数组

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/liu709127859/article/details/82619938

<script>

//方法

var test=function(){

console.log('test function');

}

function test2(){

console.log("test2 function");

}

test();

test2();

//对象{}

var person={"name":"tom","age":"18"};

console.log(person.name);

console.log(person['age']);

//对象中有 属性 方法

var person2={

firstName:"jone",

lastName:"Doe",

id:"5566",

fullName:function(){

return this.firstName+" "+this.lastName;

},

Phonenum:function(){

return '15668080744';

}

}

console.log(person2.id);

console.log(person2.fullName());

console.log(person2.Phonenum());

//数组 []

var person3 = Array( "Name","LangShen","AGE","28" );

var person4 = [ "Name","LangShen","AGE","28" ];

console.log(person3[2]);

console.log(person4[2]);

</script>

猜你喜欢

转载自blog.csdn.net/liu709127859/article/details/82619938