Search code examples
arraysgetjson

GetJson with Object.values with commas within text. How to get rid of these commas?


I would like to get a specific value from a JSON with GetJson but it is inserting commas within the value/text. Here is the structure of my JSON:

{"api":
{"results":10,"fixtures":
        [{"fixture_id":293298,
        "league_id":1251,
        "league":
            {"name":"CONMEBOL Libertadores",
            "country":"World",
            "logo":.....

I am trying to get the "name" value i.e. "CONMEBOL Libertadores" instead I'm getting "C,O,N,M,E,B,O,L, ,L,i,b,e,r,t,a,d,o,r,e,s".

  $(document).ready(function(){


$.getJSON("proxliberta.json", function(data) {

  $.each(data.api.fixtures, function() {

  });

  console.log(Object.values(data.api.fixtures[1].league.name));

  document.getElementById('val').innerHTML = Object.values(data.api.fixtures[1].league.name)

});

});

How can I eliminate these commas within my response? Thanks!


Solution

  • Instead of

    Object.values(data.api.fixtures[1].league.name)
    

    try changing to,

    data.api.fixtures[1].league.name
    

    Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Object/values