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 ...
随机推荐
- 如何实现调用console.log(‘good’.repeat(3))时输出goodgoodgood?
String.prototype.repeat=function(num){ return (new Array(num+1)).join(this) } console.log('good'.rep ...
- 向上取整Ceil,向下取整Floor,四舍五入Round
几个数值函数的功能实现: (1)int Ceil(float f) int Ceil(float f) { int integer = (int)f; if (f > (float)intege ...
- Android ActionBar详解(三)--->ActionBar的Home导航功能
FirstActivity如下: package cc.testsimpleactionbar2; import android.os.Bundle; import android.app.Activ ...
- linux杂记(八)linux压缩与打包
linux系统常见的压缩指令 一般被压缩过的档案,通常其附档名都是[*.tar,*.tar.gz,*.tgz,*.gz,*.Z,*.bz2]等等. *.tar:tar程序打包的数据.并没有压缩过 *. ...
- 常用ajax请求
JQuery版本的ajax请求:(包括处理WebService中xml字符串) $.ajax({ type: "POST", async: true, url: "&qu ...
- MySQL 表分区的几种方法和注意
分区方法1:Hash分区 例子: create table thash(x int ,y int) partition by hash(x) partitions 4; 就这么一句话表就分好区了.下一 ...
- easyui-layout中的收缩层无法显示标题问题解决
先看问题描述效果图片: 如上,我的查询条件是放在layout下面的一个可收缩层中,初始是收缩的,title显示不出来的话对使用者很不方便,代码如下: <div id="__MODULE ...
- Genymotion配置及使用教程(最新最完整版附各部分下载地址)
Genymotion配置及使用教程(最新最完整版附各部分下载地址) FROM:http://blog.csdn.net/beiminglei/article/details/13776013 早都听说 ...
- openStack icehouse for centos6.4 production Env 实战
production Env brief Overview: Management Node: controller.cc 10.114.100.115 Neutron Network Node: ...
- Java图形化界面设计——布局管理器之BorderLayout(边界布局)