日期:2014-05-16 浏览次数:20388 次
a["城市"]="北京"; a["面积"]=16800; a["人口"]=1600;
var a=[1,2,3,4]; a['foo']='Hello World'; alert(a.length);
$a=array(1,2,3,4); $a["foo"]="Hello world"; echo count($a);
var news = { id:'101', title:'这是标题', content:'这里是内容'} for(var n in news){ document.write(n+'---'+news[n]+'<br>') }
var news = { 0:{id:'101', title:'这是标题111', content:'这里是内容111'}, 1:{id:'101', title:'这是标题222', content:'这里是内容222'}, 2:{id:'101', title:'这是标题333', content:'这里是内容333'} } for(var n in news){ document.write(n+'---'+news[n].title+'<br>') } /////调用值的方法 news.id 或 news['id']
s = '{"address":"","email":"123@123.com","name":"test5","id":"6"};'; eval('o='+s); alert(o.name); 或: data=eval('(' +s+ ')');
var empty = {}; // An object with no properties var point = { x:0, y:0 }; var circle = { x:point.x, y:point.y+1, radius:2 }; var homer = { "name": "Homer Simpson", "age": 34, "married": true, "occupation": "plant operator", 'email': homer@example.com }; var a = new Array(); // Create an empty array var d = new Date(); // Create an object representing the current date and time var r = new RegExp("javascript", "i"); // Create a pattern-matching object
var book = new Object(); //创建对象 book.title="JavaScript: The Definitive Guide"; book.chapter1=new Object(); //作为对象属性的,嵌套对象 book.chapter1.title = "Introduction to JavaScript"; book.chapter1.pages = 11; book.chapter2 = { title: "Lexical Structure", pages: 6 }; alert("Outline: " + book.title + "\n\t" + "Chapter 1 " + book.chapter1.title + "\n\t" + "Chapter 2 " + book.chapter2.title); // 从对象中读取一些属性.