Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

273
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!