How to access the properties of an object in Javascript
Javascript has three different kinds of properties: named data property, named accessor property and internal property. There are two kinds of access for named properties: get and put, corresponding to retrieval and assignment, respectively. Please refer to the Ecma-262.pdf.
Here are the ways of accessing named data property.
var obj = {
property_1: 123
};
You can get its value like the following:
obj.property_1;
Or
obj[“property_1”]; //please note, quote is required here
but you have to use [“xxx”] if you intend to use for/in to access the properties of an object
for(p in obj)
{
alert(obj[p]);
}
The system will alert undefined if you access like the following within the for/in, the reason is javascript pass the property as string
for (p in obj)
{
alert(obj.p);
}
How to access the properties of an object in Javascript的更多相关文章
- [ES2017] Iterate over properties of an object with ES2017 Object.entries()
The Object.entries() function is an addition to the ECMAscript scpec in Es2017. This allows us to it ...
- 向json中添加新的熟悉或对象 Add new attribute (element) to JSON object using JavaScript
How do I add new attribute (element) to JSON object using JavaScript? JSON stands for JavaScript Obj ...
- IOS Object和javaScript相互调用
在IOS开发中有时会用到Object和javaScript相互调用,详细过程例如以下: 1. Object中运行javascript代码,这个比較简单,苹果提供了非常好的方法 - (NSString ...
- What is the most efficient way to deep clone an object in JavaScript?
What is the most efficient way to deep clone an object in JavaScript? Reliable cloning using a libra ...
- How to Get SharePoint Client Context in SharePoint Apps (Provider Hosted / SharePoint Access ) in CSOM (Client Side Object Model)
http://www.codeproject.com/Articles/581060/HowplustoplusGetplusSharePointplusClientplusContex Downlo ...
- What is an Activation object in JavaScript ?
********************* from Professional JavaScript for Web Development Execution Context And Scope T ...
- object in javascript
枚举对象属性 for....in 列举obj的可枚举属性,包括自身和原型链上的 object.keys() 只列举对象本身的可枚举属性 创建对象的几种方式 对象字面量 const pre='test' ...
- Iterable object of JavaScript
数组是可迭代的,所以数组可以用于for of,字符串也是可迭代的,所以字符串也可以用作for of,那么,对象呢? 试一试: var somebody = { start:0, end:100 } f ...
- JavaScript技巧手冊
js小技巧 每一项都是js中的小技巧,但十分的有用! 1.document.write(""); 输出语句 2.JS中的凝视为// 3.传统的HTML文档顺序是:documen ...
随机推荐
- 官网下载旧版本的Xcode
1.登录“苹果开发者中心”——>“SDKs” 2.点击“Xcode” 3.点击页面顶部的“Download” 4.点击页面左下方的“additional tools”,这样就可以查询到各个Xco ...
- Linux常用指令(待补充)
1.cd进入目录 2../shuntdown.sh 停止tomcat 3.ps -ef |grep +进程名 查看进程状态 4.kill +进程名 强杀kill -9 +进程 5./start ...
- 浏览器中输入Google.com然后按下回车键
按下回车键,当然会产生操作系统的中断响应,产生一个WM_KEYDOWN消息,当然这些都不是计算机网络的东西,这里只讨论计算机网络相关的东西: 解析URL 浏览器通过URL能够知道下面的信息: Prot ...
- jQuery给table中的负数标红色
<table class="tb_list"></table> $(function(){ $(".tb_list td").each( ...
- Mad Lib程序
单选框 复选框 按钮 标签 文本框的应用 #coding=utf-8 __author__ = 'minmin' from Tkinter import * class Application ...
- POJ 1743 Musical Theme(后缀数组+二分答案)
[题目链接] http://poj.org/problem?id=1743 [题目大意] 给出一首曲子的曲谱,上面的音符用不大于88的数字表示, 现在请你确定它主旋律的长度,主旋律指的是出现超过一次, ...
- makefile简单helloworld
最近要在unix系统上开发c++应用程序,但默认情况下unix编译c++程序需要使用makefile.其实makefile语法还是比较简单,看上去有点像ant.废话不说了,直接上helloworld. ...
- ThinkPad x200为何总是CPU占用50%
2009年,我从美国买回一台ThinkPad X200 Tablet,Windows XP Tablet PC Edition 2005版,服役几年一直很正常.直到2012年初的时候,突然发现电脑非常 ...
- java 基本语法元素
单行注释: // 多行注释: /* */ java文档: /**JAVA文档 *注释 */ : : 类似于中文的句号. 语句块:语句块也叫做复合语句 ...
- PHP批量下载方法
PHP批量下载方法 界面: $.get(“< ?php echo url::base(true);?>inventory/report/buildCsv”, //后台路径 {‘para ...