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 ...
随机推荐
- [Java]HashMap的两种排序方式
先将 Map 中的 key 和 value 全部取出来封装成 JavaBea 数组,再将这个数组排序,排序完成后,重新写回 Map 中,写回时采用 LinkedHashMap 可以保证迭代的顺序. 下 ...
- Object-c的一些基本概念
自学了一个多月的IOS,对Object-C也有了初步的认识,也有很多观点不知道是否正确,所以整理了一下,和小伙伴们分享分享 1.OC中使用的消息机制代替调用方法 区别:使用消息结构的语言,其运行时缩引 ...
- 四轴飞行器1.2.3 STM32F407时钟配置和升级标准库文件
原创文章,欢迎转载,转载请注明出处 这个星期进度比较慢哈,只有周末和晚上下班回来才能做,事件不连续,琐碎的事情又比较多,挺烦的,有多琐碎呢? 1.本人有点小强迫症哈,虽然RTT将文 ...
- VS Code - Debugger for Chrome
VS Code - Debugger for Chrome调试JavaScript的两种方式 VS Code - Debugger for Chrome调试JavaScript的两种方式 最近由于 ...
- OSCache报错error while trying to flush writer
Struts2.3+spring3+hibernate3开发现在想在原有基础上使用 oscache提高性能,使用中发现问题例如:使用struts2标签<cache:cache time=&quo ...
- ssm框架理解
SSM框架理解 最近两星期一直在学JavaEE的MVC框架,因为之前学校开的JavaEE课程就一直学的吊儿郎当的,所以现在真正需要掌握就非常手忙脚乱,在此记录下这段时间学习的感悟,如有错误,希望大牛毫 ...
- Lua环境配置 windows + VS
环境搭建: 首先从 http://www.lua.org/ftp/下载lua 源码, 我选择的是lua-5.1.5.tar.gz 我的开发环境是Win7+ VS2010 打开VS2010新建一个工程L ...
- ios网络学习------8 xml格式数据的请求处理 用代码块封装
#pragma mark 载入xml - (void)loadXML { //获取网络数据. NSLog(@"load xml"); //从webserver载入数据 NSStri ...
- div中央
.histroyMsgSearch{ background:#Fff; text-align: center; } CSS 怎样使DIV层水平居中 今天用CSS碰到个非常棘手的问题,DIV本身未定义 ...
- 延迟N秒执行某个方法
[self performSelector:<#(nonnull SEL)#> withObject:<#(nullable id)#> afterDelay:<#(NS ...