javascriptyoutube-apiyoutube-data-apiandroid-youtube-api

Youtube.Search.list(..).getItems return a String? how to easily transform or filter items?


I call YouTube Data API and get this error:

searchResults.getItems().map(item => item.id.videoId)};

searchResults.getItems(...).map is not a function

items are a String? how can I easily transform or filter items?

enter image description here


Solution

  • The code:

    var a = [0], b = [1], c = a + b;
    console.log(typeof(c));
    

    produces string on console. This one:

    var a = {};
    console.log(String(a.map));
    a.map();
    

    produces the line:

    undefined
    

    along with the error message:

    TypeError: a.map is not a function
    

    The same things happen when having var a = ""; instead.

    You should replace:

    searchResults['items'] =
    searchResults['items'] + nextPage['items'];
    

    with:

    searchResults['items'] =
    searchResults['items'].concat(nextPage['items']);
    

    assuming that both searchResults['items'] and nextPage['items'] are arrays.