Find value in Javascript array

I’m struggling with a task in javascript. I want to extract the value from an array in an API. I want to get the last_price in the Monet_ADA array. Here is the data in the API.

641f0571d02b45b868ac1c479fc8118c5be6744ec3d2c5e13bd888b6.ZOMBIE_ADA: {last_price: 0.0016, base_volume: 0, quote_volume: 0}
682fe60c9918842b3323c43b5144bc3d52a23bd2fb81345560d73f63.NEWM_ADA: {last_price: 2.4e-8, base_volume: 0, quote_volume: 0}
722c45e8ba2a3c399cf09949abe74546ecb75defb8206914085dc28e.CDX_ADA: {last_price: 0.22, base_volume: 0, quote_volume: 0}
776da8416dc56107275424b009eb82353235f10ef8e0b77088fd7964.TrustCoin_ADA: {last_price: 0.00006, base_volume: 0, quote_volume: 0}
782c158a98aed3aa676d9c85117525dcf3acc5506a30a8d87369fbcb.Monet_ADA: {last_price: 1.1e-9, base_volume: 0, quote_volume: 0}
804f5544c1962a40546827cab750a88404dc7108c0f588b72964754f.VYFI_ADA: {last_price: 0.0000019, base_volume: 0, quote_volume: 0}
815f432f5d9b36e77989d0fea374292e9c8330c5146ca8500632b3cf.Squid_ADA: {last_price: ‘NA’, base_volume: 0, quote_volume: 0}
823f7c8e25ee35f368daf2c9b6b4783c1d9a763eb5227b50b095f6c2.Djedi_ADA: {last_price: ‘NA’, base_volume: 0, quote_volume: 0}
0864aa509385d78b9d83e8547424a055bb93e152a767383c6e0ea854.AINU_ADA: {last_price: ‘NA’, base_volume: 0, quote_volume: 0}

Here is my code:

const api_url = 'http://analytics.muesliswap.com/ticker';
    
     async function getMonetPrice(){
        const response = await fetch (api_url);
        const data = await response.json();
        console.log(data);
    }
    
    getMonetPrice(); 

My code doesn’t throw an error, it just returns all the data in the API. I need help parsing through the data and then returning just the last_price value in the Monet.ADA array. Please and thank you.

>Solution :

Not clear exactly what you need but hope this helps.

    const api_url = 'http://analytics.muesliswap.com/ticker';

    async function getMonetPrice() {
        const response = await fetch(api_url);
        const data = await response.json();
        console.log(
            data['782c158a98aed3aa676d9c85117525dcf3acc5506a30a8d87369fbcb.Monet_ADA']
                .last_price
        );
    }

    getMonetPrice();

Leave a Reply