Home > Web Front-end > JS Tutorial > body text

js object properties

不言
Release: 2018-03-30 16:47:17
Original
1313 people have browsed it

There are two ways to access js object properties. This article will share with you the codes for these two ways. Friends who are interested can take a look.

There are two ways to access js object properties. The code As follows:

    var test={
      name:'wzh',
      sex:'man'
    }

    var n='name';
    console.log(test[n]);//第一种:可以动态访问对象属性
    console.log(test.name);//第二种:不能动态访问对象属性
Copy after login

Related recommendations:

javascript - Is there only one way to modify the attribute name of a js object?

Detailed explanation of javascript traversing json objects Sample code for keys and arbitrary js object attributes (picture)

A brief discussion of the differences between js object attributes through dots (.) and square brackets ([])

The above is the detailed content of js object properties. For more information, please follow other related articles on the PHP Chinese website!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template