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. linux grep 指定字符串的正则表达式

    cat all_uuid_log | grep "[a-z0-9]\{32\}"

  2. hdu 4902 Nice boat 线段树

    题目链接 给n个数, 两种操作, 第一种是将区间内的数变成x, 第二种是将区间内大于x的数变为gcd(x, a[i]). 开三个数组, 一个记录区间最大值, 这样可以判断是否更新这一区间, 一个laz ...

  3. Python的maketrans() 方法

    描述 Python maketrans() 方法用于创建字符映射的转换表,对于接受两个参数的最简单的调用方式,第一个参数是字符串,表示需要转换的字符,第二个参数也是字符串表示转换的目标. 注:两个字符 ...

  4. 简单OC程序

       Foundation框架头文件的路径 1> 右击Xcode.app --> 显示包内容 2> Xcode.app/Contents/Developer/Platforms/iP ...

  5. 配置Raspbian 启用SPI I2C

    sudo vi /etc/modprobe.d/raspi-blacklist.conf 找到这两行 blacklist spi-bcm2708 blacklist i2c-bcm2708 注释掉 # ...

  6. 依赖注入(DI)和控制反转(IOC)

    依赖注入(DI)和控制反转(IOC) 0X1 什么是依赖注入 依赖注入(Dependency Injection),是这样一个过程:某客户类只依赖于服务类的一个接口,而不依赖于具体服务类,所以客户类只 ...

  7. 5_Navigation Bar

    5 // // ViewController.swift // Navigation Bar // // Created by ZC on 16/1/9. // Copyright © 2016年 Z ...

  8. HDU 5741 Helter Skelter(构造法)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5741 [题目大意] 一个01相间的串,以0开头,给出的序列每个数字表示连续的0的个数或者1的个数, ...

  9. HDU 5765 Bonds(状压DP)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5765 [题目大意] 给出一张图,求每条边在所有边割集中出现的次数. [题解] 利用状压DP,计算不 ...

  10. Eclipse连接sql server 2012数据库编程一条龙

    一.java通过jdbc连接sql server 2012 原帖地址:http://blog.csdn.net/stewen_001/article/details/19553173/ 1.sql s ...