const countryList = [{"countryId":1,"countryQuote":"USDKRW","countryCode":"KRW","countryName":"\uD55C\uAD6D"},{"countryId":2,"countryQuote":"USDJPY","countryCode":"JPY","countryName":"\uC77C\uBCF8"},{"countryId":3,"countryQuote":"USDPHP","countryCode":"PHP","countryName":"\uD544\uB9AC\uD540"}];
const currencyQuoteList = [{"countryQuote":"USDKRW","currencyRate":1162.685028},{"countryQuote":"USDJPY","currencyRate":104.40402},{"countryQuote":"USDPHP","currencyRate":48.480296}];
let itemId = 1;
let countryQuote;
let countryRate;
countryList.forEach(element => {
if(itemId == element.countryId) {
countryQuote = element.countryQuote;
}
});
console.log("countryQuote : " + countryQuote);
currencyQuoteList.forEach(element => {
if(countryQuote == element.countryQuote) {
countryRate = element.currencyRate;
}
})
console.log("countryRate : " + countryRate);
I would like to find currencyRate
using itemId
.
Const values are given by the server.
I have a countryId
in HTML, and I'd like to find currencyRate
With these 2 arrays.
Each countryQuote
key in arrays would be joinable.
I just have to find currencyRate
using brute-force searching, but I would like to improve this code.
What should do I search for it?