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 ...
随机推荐
- JavaScript知识(二)
你要保守你心,胜过保守一切,因为一生的果效,是由心发出的.————O(∩_∩)O... ...O(∩_∩)O...老师因有事下午没来上课,今天就只把中午讲的知识总结一下.由于昨天只是讲了JavaScr ...
- headfirst之装饰模式
class A A.hello class B extends A B.hello = A.hello+B 装饰模式:子类对父类想要包装的方法进行重写,使之成为加强版
- [工具] XMind
XMind是一款非常实用的思维导图软件, 高效易用的可视化思维软件; 通过XMind可以随时开展头脑风暴, 帮助人们快速理清思路, XMind可绘制的思维导图, 鱼骨图, 二维图, 树形图, 逻辑图, ...
- poj2175
鸣谢: http://www.cppblog.com/y346491470/articles/152317.html [题意]:一个城市有n座建筑物,每个建筑物里面有一些人,为了在战争爆发时这些人都可 ...
- Knuth-Morris-Pratt Algorithm
Today , 第一次学习KMP Algorithm,其中好多地方还是不能理解的透彻,本文将进一步对 KMP Algorithm 进行学习,搞清楚其中的思想…… First , KMP Algorit ...
- nginx install
./configure --prefix=/home/allen.mh/local/nginx --with-http_ssl_module --with-http_sub_module --with ...
- CSDN博客排名第一名,何许人也
CSDN博客排名第一名,何许人也 一.提出问题 CSDN博客排名第一名,何许人也. 分析截止时间是:2013年12月19日星期四22:00. 二.博客网址 http://blog.csdn.net/p ...
- 编程习题——Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- 实验时css层叠样式表不更新的情况
自定义了CSS的样式,希望在页面中起作用.因为MVC中Views/Shared/_Layout.cshtml是所有视图的公共文件,如下: <!DOCTYPE html> <html& ...
- CCNA实验(6) -- VLAN & SPT
交换机的作用主要有两个:1.维护CAM(ContextAddress Memory)表,该表是MAC地址和交换机端口的映射表2.根据CAM进行数据帧的转发 交换机对数据帧的处理有三种:1.Forwar ...