一、代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>无标题 1</title>
<script>
var arr=[];
arr.push("hello");
document.writeln(arr.length);
var obj = {aa:"sd"};
obj.bb = 'hello';
document.writeln(obj.length);
</script>
</head>
<body>
</body>
</html>
二、结果:
输出的是
1
undefined
原因是因为系统对象Array含有属性length,而自己建的对象没有定义属性length。