The following function can be used to return value from an array by giving another key and value.
/**
* search for the country code from search results
* @param {*} array
* @param {*} value
* @param {*} key
*/
function filter(array, value, key) {
return array.filter(key ? function (a) {
return a[key] === value;
}
: function (a) {
return Object.keys(a).some(function (k) {
return a[k] === value;
});
});
}