Home  >  Article  >  Web Front-end  >  js object properties

js object properties

不言
不言Original
2018-03-30 16:47:171270browse

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);//第二种:不能动态访问对象属性

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!

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