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. PHP GUID的生成源码

    <?php function guid(){ if (function_exists('com_create_guid')){ return com_create_guid(); }else{ ...

  2. firebug如何使用

    1.怎么安装firebug: a.打开火狐浏览器--------b.点击火狐浏览器的右上角这个小图标-------c.点击<获取附件组件>,在右上角的搜索框()内,输入firebug,点击 ...

  3. [转]WIN7系统安装Apache 提示msvcr110.DLL

    我的系统是WIN7 64位,安装配置Apache2.4.7(httpd-2.4.7-win64-VC11.zip )提示如下错误 VC++2012 2013 百度网盘地址:http://pan.bai ...

  4. perl lwp get uft-8和gbk

    gbk编码: jrhmpt01:/root/lwp# cat x2.pl use LWP::UserAgent; use DBI; $user="root"; $passwd='R ...

  5. POJ 3450 Corporate Identity(KMP)

    [题目链接] http://poj.org/problem?id=3450 [题目大意] 求k个字符串的最长公共子串,如果有多个答案,则输出字典序最小的. [题解] 我们对第一个串的每一个后缀和其余所 ...

  6. Course(简单的字符串处理问题)

    Course 时间限制:1000 ms  |  内存限制:65535 KB [问题描述] There is such a policy in Sichuan University that if yo ...

  7. PHP批量下载方法

      PHP批量下载方法 界面: $.get(“< ?php echo url::base(true);?>inventory/report/buildCsv”, //后台路径 {‘para ...

  8. Seoer,牵起用户与搜索引擎双手的魔术师

    SEOer:牵起用户与搜索引擎双手的魔术师 我想这是你的第一个疑问. SEO不是针对搜索引擎的技术吗?与用户有什么样的关联呢?又为何称他作魔术师呢?假设你有这些疑问.这篇文章就值得你阅读.SEO.搜索 ...

  9. cocos2d-x 3.0 新特性样例

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzMyMTMyOA==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  10. Github实例教程-创建库、创建主页

    以README文件为实例,具体介绍github的使用过程 请先下载git,然后配置下面内容: ( 我的系统是debian,其它版本号的UNIX/Linux有区别),windows的临时不清楚. (一) ...