简体   繁体   中英

javascript can't get object property value

I have javascript object like below:

var row = {
              'fileAttribute' : {
                  '.\K\ar- #%i\.n/a': true,
                  'size': '2040',
                  'type' : 'pdf'
                  }
    };

But when I try to get value of row.fileAttribute['.\\K\\ar- #%in/a'] , I get undefined instead of true.

I know that it's beacuse my property name contains a special characters. row.fileAttribute.hasOwnProperty('.\\K\\ar- #%in/a') returns false.

I tried to extract this property values by _.values(row.fileAttribute['.\\K\\ar- #%in/a']) , however I got empty array.

My console: 在此处输入图片说明

Here is a example of this issue:

http://jsfiddle.net/fvu2pqzz/8/

I appreciate any help, thanks!

You need to use bracket notation

console.info(row.entity.fileAttribute['.Kar- #%i.n/a']);

 var row = { 'entity' : { 'fileAttribute' : { '.\\K\\ar- #%i\\.n/a': true, 'size': '20', 'qty' : '50' }, 'part2' : { 'name': 'Part 2', 'size': '15', 'qty' : '60' } } }; console.info(row.entity.fileAttribute['.Kar- #%in/a']); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM