javascript - finding a value in an object -
i have object:
{ id: 16, defs: { name: "depot (float)", field: "depot" } }
and array (which can have more 1 object in purposes of has one):
[ { percentage monthly potential: 1, area manager: "ashar", business unit: "retail", cust no: 68345, depot name: "leicester", group number: "", depot: 14, target: 46100 } ]
what need take field value object , use find key matches in second object , retrieve value of it, in case should getting 14.
any appreciated.
thanks time.
if using es6, can try this:
const field = lookupobject.defs.field; const matches = array.map(arrayitem => { return { field, value: arrayitem[field] } });
the matches
array contain data interested in.
Comments
Post a Comment