javascript - $.grep returning undefined when comparing ID to variable -


i have $.each loop in code loops through items in 1 array , tries find corresponding items in array. 1 array structure array, items need. other array contains items have value associated.

i tried following code:

$.each(placementstructurehaspitems, function () {     var haspitem = $.grep(placementvalueshaspitems, function (e) {         return e.haspid === this.haspid;     })[0];     if (haspitem != undefined) {         this.commentspretext = haspitem.commentspretext;     } }); 

haspitem undefined, every object. cannot post image of if run in console in chrome, try , format best possible, top line code entered chrome , second line result given. :

$.grep($scope.haspitemsfromplacement, function (e) { return e.haspid === this.haspid; })[0]; undefined  $.grep($scope.haspitemsfromplacement, function (e) { return e.haspid === 2; })[0]; object {haspid: 2, parentid: 1, numberingtype: 0, text: null, yesnoid: 0…}  this.haspid 2 

my main question here why grep works static number, not property of object evaluates same number.

thanks in advance help.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -