Home >Backend Development >PHP Tutorial >在JavaScript 怎么声明一个关联数组?

在JavaScript 怎么声明一个关联数组?

WBOY
WBOYOriginal
2016-06-06 20:13:01960browse

就是 php 的这种写法:

<code>$arr=Array(name=>"zhangsan",id=>"00123456",sex=>"m",age=>30);
</code>

在JavaScript里怎么写?

回复内容:

就是 php 的这种写法:

<code>$arr=Array(name=>"zhangsan",id=>"00123456",sex=>"m",age=>30);
</code>

在JavaScript里怎么写?

咦那不就是object么,

<code class="js">var obj={name:'zhangsan',id:'00123456',sex:'m',age:30}</code>

应该是JSON吧?JSON有两种格式,一种是对象的表示法,另一种是数组的表示法。楼主说的是数组,应该就是JSON的数组表示法了,格式如下:

<code>var arr = [
    {
        name:"zhangsan",
        id:"00123456",
        sex:"m",
        age: 30
    }
]</code>

js里的数组下标只能是数字,所以想要实现类似功能就用object吧。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn