Jump to content

Load youtube playlist with javascript. (sometimes it shows one thing as an array, sometimes it shows it as an object)

mrchow19910319

I am trying to feed off a youtube playlist into the webpage, this is the response I get from the API call:

 

Spoiler

296434779_apicall.png.e970a5e7007845d9d42ec84852a04c3d.png

notice that "items" is an array in the picture.

but the result i get from: 

console.log(typeof data.items);

is object. 

 

in this picture it shows data.items is array

 

Spoiler

array.png.53d7b05047408a91c2bc0ff14f11083e.png

so what it is then?? Array or object? 

If it is not broken, let's fix till it is. 

Link to comment
Share on other sites

Link to post
Share on other sites

/*  
Load Playlist
*/

function loadPlayList(data) {

  console.log(data.items);
  console.log(typeof data.items);

  data.items.forEach(
    function (item, index, array) {

      var thumbnail = data.items.snippet.thumbnails.medium.url;

      document.getElementById('youtube_playlist').innerHTML = `
      <div class="individual_list_item">
      <img src="${thumbnail}" alt="video_thumbnail_placeholder" class="thumbnails">
      <div class="video_descriptions">
        <h4 class="playlist_titles">Video Titles</h4>
        <p class="playlist_descriptions">asd</p>
      </div>
    </div>
      `;
    }


  );

}

 

If it is not broken, let's fix till it is. 

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, duncannah said:

Arrays are technically objects, that's why typeof returns an object

shit I forgot about that.

If it is not broken, let's fix till it is. 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×