javascript - Access object using dynamic object name -
this question has answer here:
i have object data inside. first level of data 2 arrays (body, cause). each body , cause array have arrays inside of them (date, year).
totals:[{body:[ {date:[54,9,3,17]}, {year:[437,61,31,140]}]}, {cause:[ {date:[54,9,3,17]}, {year:[437,61,31,140]}] }]
what access body/cause array dynamically based on user has changed.
this how accessing them now.
totals[iscause].body[isyear].date[filternumber]);
my issues body , date hard coded in there, , have access either body/cause date/year. can't seem find these property names stored as. tried set var , this
var bodycause = "body";
then tried pass retriever statement.
totals[iscause].bodycause[isyear].date[filternumber]);
but fails. i'm trying figure out property name stored , if can dynamically set when need retrieve information.
your attempt correct. can easyly use var bodycause = "body";
, access content dynamically. instead of this
totals[iscause].bodycause[isyear].date[filternumber]);
you should use this
totals[iscause][bodycause][isyear].date[filternumber]);
should fix problem.
Comments
Post a Comment