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 ...
随机推荐
- IOS开发之Cocoa编程—— NSUndoManager
在Cocoa中使用NSUndoManager可以很方便的完成撤销操作.NSUndoManager会记录下修改.撤销操作的消息.这个机制使用两个NSInvocation对象栈. NSInvocation ...
- WCF遇到Oracle问题
解决 选中下图中对网站和项目使用IIS….64位版
- VS2013 快捷键 VS RESHARPER 设置
一直用Resharper插件,最近发现Ctrl+E,C快捷见被Resharper的快捷功能吞掉了,折腾了几小时终于找到解决方法了,特记分享之. 采用如下步骤可以让快捷键回到vs2012的默认方式,同时 ...
- IO库 8.5
题目:重写8.4中的函数,将每一个单词作为一个独立的元素进行存储. #include <iostream> #include <fstream> #include <st ...
- Java 注解机制
一.注解中的信息已经在Class中了,我们应该如何读取出来 java.lang.reflect.AnnotatedElement接口: public Annotation[] getAnnotatio ...
- 1.PHP 教程_PHP 简介
PHP是服务器端脚本语言. 在学习之前,您需要对以下知识有基本的了解: HTML css PHP是什么? PHP代表PHP:Hypertext Preprocessor PHP是一种使用广泛的开源的脚 ...
- 应该知道的Linux技巧
作者:陈皓(花名:钻风) 这篇文章来源于Quroa的一个问答<What are some time-saving tips that every Linux user should know?& ...
- Chrome设计文档-多进程架构
chromium multi-process architecture 本文档从high-level的角度描述Chromium的多进程架构. 问题 要构建一个决不崩溃或挂起的渲染引擎几乎是不可能的.同 ...
- SQL Server 镜像
sql server 2005镜像制作 以下是操作步骤:-- =========================================== -- 无论是主体服务器.镜像服务器, 还是见证服务 ...
- Html 小插件5 百度搜索代码2
网页添加百度搜索框代码大全 ★ 用法:在下面选择合适的样式,复制代码到网页中相应位置粘贴即可. ★ 样式一(200×30)代码: <iframe id="baiduframe" ...