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 ...
随机推荐
- apache rewrite rule
http://10.58.104.19:8008/site/833/3f11d2b44b7d3baa2149f26a30f8c68d/b.js?siteid=332323 将一个静态请求转换成一个动态 ...
- 表单元素的submit()方法和onsubmit事件(转)
1.表单元素中出现了name="submit"的元素 2.elemForm.submit();不会触发表单的onsubmit事件 3.动态创建表单时遇到的问题 表单元素拥有subm ...
- 尼康D5100使用设置及技巧,同样也适用尼康D5200
尼康D5100使用设置及技巧,同样也适用尼康D5200,希望对新手能有点帮助. 一.设置 1.优化校准:可以在menu菜单中找到它,一般使用"标准"就可以,建议将"标准& ...
- APM代码学习笔记2:编译过程
make编译 所有位置的Makefile 引用的都是/mk/apm.mk target.mk 设置CONFIG_HAL_BOARD 例如linux就是HAL_BOARD_LINUX environ.m ...
- Angular ng-repeat 对象和数组遍历
直接上代码 <!DOCTYPE html> <html> <head> <meta name="description" content= ...
- java调用C++ DLL库方法
最近一个项目要开发网页端人脸识别项目,人脸识别的算法已经写好,是C++版,但是网页端要求使用Java后台,这就涉及到Java调用DLL的问题.经过查找,实现了一个简单的例子. 1.第一步,先在Java ...
- Zepto Api参考
zepto API参考 简介 Zepto是一个轻量级的针对现代高级浏览器的JavaScript库, 它与jquery有着类似的api. 如果你会用jquery,那么你也会用zepto. 设计目的 ze ...
- Html 小插件3
搜狗搜索框代码 <script>function verifyquery(form){if(form.sogou_drop.value==2){form.insite.value='';} ...
- cmd dos 下 无法显示中文
在做程序开发的时候经常需要在使用命令行进行操作, dos环境本身是不支持中文的,有时候中文编码的问题就像苍蝇一样讨厌,下面提供几种常用的手段解决win7环境下中文显示乱码的问题: 方法一: 修改注册表 ...
- python 在 for i in range() 块中改变 i 的值的效果
先上一段代码: for i in range(3): i = 2 print(i) 实际结果是: 2 2 2 可以发现实际效果就是 在每次执行 for 语句块的内容后 i 会被重新赋值