trying to use es6 map method so below i am trying to get object from cacheDetails function that matches with the key but it also returns some undefined values, what is implemented wrong in below code any help would be appreciated ?
main.js
var uniqueCacheKeys = [{key:"14556459709"},{key:"1457099"}];
var rxInfos = [];
function getCahce(data){
data.forEach(function(el){
var rxInfo = cacheDetails(el.key);
if(rxInfo){
rxInfos.push(rxInfo);
}
});
}
function cacheDetails(key){
var mapObj;
var rxInfos = [
{
"drugNdc": "10101",
"rxNumber": "14556459709",
"firstFillIndicator": "N",
"sourceSystem": "TBS",
"indexID": "RPT0ifQ",
"ancilary": true
},{
"drugNdc": "10101",
"rxNumber": "145709",
"firstFillIndicator": "N",
"sourceSystem": "TBS",
"indexID": "RPT0ifQ",
"ancilary": true
}];
mapObj = rxInfos.map(function (task, index, array) {
if(task.rxNumber === key){
return task;
}
});
return mapObj;
}
getCahce(uniqueCacheKeys);
console.log(rxInfos);
output
[[[object Object] {
ancilary: true,
drugNdc: "10101",
firstFillIndicator: "N",
indexID: "RPT0ifQ",
rxNumber: "14556459709",
sourceSystem: "TBS"
}, undefined], [undefined, undefined]]
desired ouput with above data
[{
ancilary: true,
drugNdc: "10101",
firstFillIndicator: "N",
indexID: "RPT0ifQ",
rxNumber: "14556459709",
sourceSystem: "TBS"
}]