javascript - How do I add new properties to an array of objects? I'm trying to use $.map -
i have array of 1300+ objects. these objects jeans properties such waist, knee, thigh, , cuff measurements.
i'm looking add 4 new properties each object in array:
var getresults = function(){ results = $.map(dbcontent,function(i){ (i).riseprox = "0"; (i).thighprox = "0"; (i).kneeprox = "0"; (i).cuffprox = "0"; when run this, says riseprox undefined. i'm trying add these 4 new properties every object. please help. :)
var getresults = function(){ results = $.map(dbcontent,function(i){ //create counter proximity (i).riseprox = 0; (i).thighprox = 0; (i).kneeprox = 0; (i).cuffprox = 0; //start iterating , adding counter //check rise if ((i).rise >= (psobject.rise-qinch) && (i).rise <= (psobject.rise+qinch)){ riseprox+=3} else if ((i).rise >= (psobject.rise-hinch) && (i).rise <= (psobject.rise+hinch)){ riseprox+=2} else if ((i).rise >= (psobject.rise-inch) && (i).rise <= (psobject.rise+inch)){ riseprox++}; //check thigh if ((i).thigh >= (psobject.thigh-qinch) && (i).thigh <= (psobject.thigh+qinch)){ thighprox+=3} else if ((i).thigh >= (psobject.thigh-hinch) && (i).thigh <= (psobject.thigh+hinch)){ thighprox+=2} else if ((i).thigh >= (psobject.thigh-inch) && (i).thigh <= (psobject.thigh+inch)){ thighprox++}; //check knee if ((i).knee >= (psobject.knee-qinch) && (i).knee <= (psobject.knee+qinch)){ kneeprox+=3} else if ((i).knee >= (psobject.knee-hinch) && (i).knee <= (psobject.knee+hinch)){ kneeprox+=2} else if ((i).knee >= (psobject.knee-inch) && (i).knee <= (psobject.knee+inch)){ kneeprox++}; //check cuff if ((i).cuff >= (psobject.cuff-qinch) && (i).cuff <= (psobject.cuff+qinch)){ cuffprox+=3} else if ((i).cuff >= (psobject.cuff-hinch) && (i).cuff <= (psobject.cuff+hinch)){ cuffprox+=2} else if ((i).cuff >= (psobject.cuff-inch) && (i).cuff <= (psobject.cuff+inch)){ cuffprox++}; //create totalprox evaluate total proximity or likeness in size i.totalprox = i.riseprox + i.thighprox + i.kneeprox + i.cuffprox; console.log(i.totalprox) }); };
this entire function. i'm trying compare psobject (selected jean size) every jean in database determine jeans closest match. intended creating riseprox etc. properties , increasing them 1, 2, , 3 depending on how close matches are.
i dont see returning (i) item $.map function.
also see mapping using reduce this:
var getresults = function(){ return dbcontent.reduce(function(mapped, item){ item.riseprox = "0"; item.thighprox = "0"; item.kneeprox = "0"; item.cuffprox = "0"; mapped.push(item); return mapped; }, []); };
Comments
Post a Comment