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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:13:01
Original
992 people have browsed it

就是 php 的这种写法:

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

在JavaScript里怎么写?

回复内容:

就是 php 的这种写法:

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

在JavaScript里怎么写?

咦那不就是object么,

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

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

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

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

Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template