<!DOCTYPE html>
<html>
<body>
<h1>JavaScript 建立数组与对象</h1>
<p>JavaScript</p>
<p id="demo"></p>
<script>
/*
var sen={e:"e",c:"c"};
这样是不可以的。这样3个数组会指向同一地址。
var sentence=[sen,sen,sen];
*/
/*分配空间*/
var sen={e:"e",c:"c"};
var sentence=[];
/*k分配对象个数*/
for(var k=0;k<10;k++)
{
sentence.push(JSON.parse(JSON.stringify(sen)));
}
var word = {eng:"English", chn:"英文",sentence};
var i=0;
sentence[0].e="This is English.";
sentence[0].c="这是英文。";
sentence[1].e="English is important";
sentence[1].c="英语很重要。";
sentence[2].e="I can't speak in English.";
sentence[2].c="我不会说英语";
/*
for(i=0;i<3;i++)
{
alert(sentence[i].e);
}
*/
var show="";
show+=word["eng"]+"<br>";
show+=word["chn"]+"<br><br>";
show+=word["sentence"][0].e+"<br>";
show+=word["sentence"][0].c+"<br>";
show+=word["sentence"][1].e+"<br>";
show+=word["sentence"][1].c+"<br>";
show+=word["sentence"][2].e+"<br>";
show+=word["sentence"][2].c+"<br>";
document.getElementById("demo").innerHTML = show;
</script>
</body>
</html>