typescript - JavaScript map(), undefined property of object from the collection -


i have collection of filter objects this.selectedfilters.

i use js map method select field property of filter object.

 console.log(this.selectedfilters.map((val) => {             console.log(val);             console.log(val.field);             console.log(val['field']);             return val.field;         })); 

the result is:

enter image description here

can tell me why val.field gives undefined value? :(

ps: used typescript

update:

i think know why val string. maybe it's because this.selectedfilters ng-model of select html element (multiple enabled) options having object value. maybe option value converted object json string when transferred this.selectedfilters model

the answer val string containing json see in console. if object, console output different.

it looks need put json.parse in there. haven't shown original typescript, in javascript this:

console.log(this.selectedfilters.map((val) => {     val = json.parse(val);    // <====     console.log(val);     console.log(val.field);     console.log(val['field']);     return val.field; })); 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -