Here is such a small script that I get data from html and I want to transfer it to the map then, but the Object object is displayed in alert() , and not my value. How do you guys fix it? Here is my code

 var map; var x= -34.397; var his=$('td').eq(19).each(function(){ console.log($(this).html()); }); function initMap() { map = new google.maps.Map(document.getElementById('map'), { center: {lat:x, lng: 150.644}, zoom: 8 }); }; alert(his); initMap(); 

    1 answer 1

    Try this:

     var map; var x= -34.397; var his = $('td').eq(19).html(); function initMap() { map = new google.maps.Map(document.getElementById('map'), { center: {lat:x, lng: 150.644}, zoom: 8 }); }; alert(his()); initMap(); 

    You have displayed the td object itself to which you referred. It is necessary that the value of the function be displayed.

    • Yuri, how many years have you been practicing on js and jquery - elik
    • @elik, 2-3 years. Why? - Yuri
    • Just wondering. Curious) - elik
    • It did not work. He returned such an answer function { - elik
    • one
      @elik, because you had to call the function: alert(his()); - Grundy