Home  >  Article  >  Web Front-end  >  What are property values ​​of javascript objects

What are property values ​​of javascript objects

WBOY
WBOYOriginal
2022-06-22 10:25:172026browse

The property values ​​of javascript objects refer to the values ​​related to JavaScript objects; JavaScript objects are collections of unordered properties. Property values ​​can usually be modified, added and deleted, but some properties are read-only. The syntax for accessing object properties is "objectName.property", "objectName["property"]" or "objectName[expression]".

What are property values ​​of javascript objects

The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.

What are the property values ​​of javascript objects

Properties are the most important part of any JavaScript object.

Properties refer to values ​​associated with JavaScript objects.

JavaScript objects are collections of unordered properties.

Properties can generally be modified, added, and deleted, but some properties are read-only.

The syntax for accessing object properties is:

objectName.property           // person.age

or:

objectName["property"]       // person["age"]

or:

objectName[expression]       // x = "age"; person[x]

The expression must evaluate to the property name.

The example is as follows:

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript 对象属性</h1>
<p>访问对象属性有两种不同的方法:</p>
<p>您可以使用 .property 或 ["property"]。</p>
<p id="demo"></p>
<script>
var person = {
  firstname:"Bill",
  lastname:"Gates",
  age:62,
  eyecolor:"blue"
};
document.getElementById("demo").innerHTML = person.firstname + " is " + person.age + " years old.";
</script>
</body>
</html>

Output result:

What are property values ​​of javascript objects

##[Related recommendations:

javascript video tutorialwebfrontend

The above is the detailed content of What are property values ​​of javascript objects. 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