J
J
jizzy2020-05-07 00:51:27
JavaScript
jizzy, 2020-05-07 00:51:27

How do I get 2 elements out of an array while specifying another element in the same array?

{"exchangeRate":{"baseCurrency":"UAH","currency":"EUR","saleRateNB":18.7949200,"purchaseRateNB":18.7949200,"saleRate":20.0000000,"purchaseRate":19.2000000},{"baseCurrency":"UAH","currency":"GEL","saleRateNB":8.1500890,"purchaseRateNB":8.1500890},{"baseCurrency":"UAH","currency":"PLZ","saleRateNB":4.4922010,"purchaseRateNB":4.4922010,"saleRate":5.0000000,"purchaseRate":4.2000000}]}


I need to output only the euro parameter and its two parameters saleRateand purchaseRate.
How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Klimenko, 2020-05-07
@jizzy

const rawObject = {
    exchangeRate: [
        {
            baseCurrency: 'UAH',
            currency: 'EUR',
            saleRateNB: 18.7949200,
            purchaseRateNB: 18.7949200,
            saleRate: 20.0000000,
            purchaseRate: 19.2000000
        },
        {
            baseCurrency: 'UAH',
            currency: 'GEL',
            saleRateNB: 8.1500890,
            purchaseRateNB: 8.1500890
        },
        {
            baseCurrency: 'UAH',
            currency: 'PLZ',
            saleRateNB: 4.4922010,
            purchaseRateNB: 4.4922010,
            saleRate: 5.0000000,
            purchaseRate: 4.2000000
        }
    ]
};

const euro = rawObject.exchangeRate.find(obj => (obj.currency === 'EUR'));

console.log(euro);
console.log(`Euro saleRate: ${euro.saleRate}`);
console.log(`Euro purchaseRate: ${euro.purchaseRate}`);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question