获取两个 url Java 脚本

Fetch Two urls Java script

如何从这个数组中调用数据?? 我必须从其他网址添加两个值。 enter image description here

<table id="sales_table">
  <thead>
    <tr id="sales_item_title"></tr>
  </thead>
  <tbody>
    <tr id="sales_item"></tr>
  </tbody>
</table>
<script>
  async function init(){
  try{
      const results = await Promise.all([

        fetch('https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=PLN').then((response)=> response.json()),

        fetch('https://min-api.cryptocompare.com/data/all/coinlist')
        .then((response)=> response.json()),

      ].map(promise=>promise.catch(error=>console.error)));

      console.log(results);
      document.querySelector('#sales_item').innerHTML = results.0.PLN

    } catch (error) {
      console.error(error);
    }
  }
  init();
</script>

您 return 两个对象,并且您可以通过密钥访问该对象。在您的示例中 PLN 。然后使用:object.PLN.

async function init() {
    const first = await fetch('https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=PLN')
    .then((response)=> response.json());

    const second = await fetch('https://min-api.cryptocompare.com/data/all/coinlist')
     .then((response)=> response.json());

    let merged = {...first, ...second};
    console.log(merged);    
    console.log('PLN:',merged.PLN)
}

init()
    .catch(e => {
        console.log('some problems: ' + e.message);
    });