json - How do I access an object property dynamically using a variable in JavaScript? -
i’m trying filter data json in javascript.
i define variable a
. want property of whatever value a
equal (not item.a
). far i’ve been unable find way of doing it.
everything else working correctly because when changed specific entry (item.date example) works fine. cannot figure out correct syntax.
while(i< elements.length){ var a=elements[i].id; if(elements[i].name == 'targetfeild'){ $(elements[i]).val($.map(result,function(item){var test = elements[i].id;return item.a;})); } i++; }
try item[a]
, javascript objects can accessed way.
Comments
Post a Comment