Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

280
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda