Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

275
Visualizações
JavaScript - How do I access a value in an array, containing an object that contains and array of objects?? I need a property of one of the objects

screengrab of console output of actual array

I'm new to JS and am trying to get a value from inside of the array.

In the console I enter:

assetList[0].data[0].id 

and I get back the value as I expect to, however when I try to pass the value into a variable in my actual JS script as per below:

function getAssetList() {

var myHeaders = new Headers();  
myHeaders.append("Authorization", "Basic 12345678==");

var requestOptions = {
  method: 'GET',
  headers: myHeaders,
  redirect: 'follow'
};
assetList.pop(); //remove the existing data from the array first otherwise it will keep adding assset lists to the array
fetch("https://api.mux.com/video/v1/assets", requestOptions)
  .then(response => response.json())
  .then(data => assetList.push(data))
  .catch(error => console.log('error', error));

  let assetListData = assetList[0].data[0].id;

  // find the unordered list in the HTML
   let assetListContents = document.getElementById("assetListContents");
   //get the length of the array
   let arrayLength = 25 //assetList[0].data.length;
   //use a loop to go through array and add 
      
  for( let i=0; i < arrayLength; i++) {
      let listItem = document.createElement("li");
      listItem.innerHTML = assetListData;
      assetListContents.append(listItem);
  }

};

I get an error back, Uncaught TypeError: Cannot read properties of undefined (reading 'data')

The error happens at "let assetListData = assetList[0].data[0].id;" What am I doing wrong here? Thanks for your help!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda