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:
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
Post a Comment