JS 兩種陣列型別
阿新 • • 發佈:2019-02-11
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<script>
var array1 = [123, 'abc'];
alert(array1[0]);
var array2 = {
Name: "zhangsan",
Age:15
}
alert(array2["Name"]);//通過鍵訪問,認為是集合
alert(array2.Name);//通過屬性訪問,認為是物件Json
//定義JSON陣列
var temp = [
{ Name: "zhansan", Age: 12 }, { Name: "lisi", Age: 30 }, { Name: "wangwu", Age: 90 }];
for (var index in temp) {
alert(temp[index].Name + "===" + temp[index].Age);
}
</script>
</body>
</html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<script>
var array1 = [123, 'abc'];
alert(array1[0]);
var array2 = {
Name: "zhangsan",
Age:15
}
alert(array2["Name"]);//通過鍵訪問,認為是集合
alert(array2.Name);//通過屬性訪問,認為是物件Json
//定義JSON陣列
var temp = [
{ Name: "zhansan", Age: 12 }, { Name: "lisi", Age: 30 }, { Name: "wangwu", Age: 90 }];
for (var index in temp) {
alert(temp[index].Name + "===" + temp[index].Age);
}
</script>
</body>
</html>