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的更多相关文章

  1. [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 ...

  2. 向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 ...

  3. IOS Object和javaScript相互调用

    在IOS开发中有时会用到Object和javaScript相互调用,详细过程例如以下: 1. Object中运行javascript代码,这个比較简单,苹果提供了非常好的方法 - (NSString ...

  4. 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 ...

  5. 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 ...

  6. What is an Activation object in JavaScript ?

    ********************* from Professional JavaScript for Web Development Execution Context And Scope T ...

  7. object in javascript

    枚举对象属性 for....in 列举obj的可枚举属性,包括自身和原型链上的 object.keys() 只列举对象本身的可枚举属性 创建对象的几种方式 对象字面量 const pre='test' ...

  8. Iterable object of JavaScript

    数组是可迭代的,所以数组可以用于for of,字符串也是可迭代的,所以字符串也可以用作for of,那么,对象呢? 试一试: var somebody = { start:0, end:100 } f ...

  9. JavaScript技巧手冊

    js小技巧 每一项都是js中的小技巧,但十分的有用! 1.document.write(""); 输出语句  2.JS中的凝视为//  3.传统的HTML文档顺序是:documen ...

随机推荐

  1. C++ HttpServlet 高并发多线程 HTTP 服务器(转)

    from:http://www.oschina.net/code/snippet_568966_43193   C/C++ 程序虽然执行效率高,但程序员在开发 WEB 应用时却因为没有好的 WEB 开 ...

  2. Android应用如何开机自启动、自启动失败原因

    本文主要介绍Android应用如何开机自启动.自启动失败的原因.adb命令发送BOOT_COMPLETED.问题:应用程序是否可以在安装后自启动,没有ui的纯service应用如何启动?答案马上揭晓^ ...

  3. javascript函数apply和call

    apply:方法能劫持另外一个对象的方法,继承另外一个对象的属性. Function.apply(obj,args)方法能接收两个参数obj:这个对象将代替Function类里this对象args:这 ...

  4. android-通知Notification

    发送通知 public class MyActivity extends Activity { @Override protected void onCreate(Bundle savedInstan ...

  5. Linux 用户信息,组信息,密码信息!

    1: 用户信息保存在  /etc/passwd 文件下 2: 密码信息保存在 /etc/shadow 3: 组相关的信息 /etc/group

  6. linux 怎么查找oracle11g的安装目录

    一般来说,/etc/oraInst.loc文件里会记录oracle的路径,如[oracle@ruby ~]$ cat /etc/oraInst.loc inventory_loc=/u01/app/o ...

  7. 使用Fiddler解析WCF RIA Service传输的数据

    原文 http://www.cnblogs.com/wintersun/archive/2011/01/05/1926386.html 使用Fiddler 2 解析WCF RIA Service传输的 ...

  8. Java学习——Ubuntu下jdk的安装以及Java环境的配置

    第一步.下载 到官网下载jdk,在Java SE Development Kit 7uXX里面,把Accept License Agreement 打勾,这样才能下载jdk,然后我们选择对应的Ubun ...

  9. c#打印记忆功能

    下面这些实例都可以拷下直接用 总体思路:保存打印设置信息到本地文件,下次打印的时候直接读取文件信息,通过序列化与反序列化来获取值.本例只是针对打印的横纵向进行设置,读者也可以增加其他设置信息进行保存读 ...

  10. android环境下解决java.io.IOException: Malformed ipv6异常的方法

    今天做客户端想服务端提交信息的时候,报出了如标题所显示的方法 方法以及参数如下: 输入的参数为:http://192.168.1.173:8080/Api/petinfo/petinfo?flag=a ...