rob.m rob.m - 2 years ago 104
Javascript Question

how to remove a comma from an object?

I tried:

val['*'].replace(/,/g , '')

But i still have the

,Битва при реке Пэккан

,Bitka kod Baekganga

,Битва при річці Пек

,Trận Bạch Giang


return val['*']

Answer Source

From what I've finally been able to grab, you are using this kind of line (stripped a bit)

$('#results').append('<li>' + curTitle + "<br>" +{ return val['*'] + "<br>" }) + '</li>');

What happens is that the result from is an array, and to concatenate that to the

  • string, its values are concatenated with the dreaded comma.

    You can see by yourself using this:

    console.log({ return val['*'] + "<br>" }).toString());

    To fix this, you have multiple possibilities, the best is to leverage jQuery's flexible append this way:

    $('#results').append('<li>' , curTitle , "<br>" ,{ return val['*'] + "<br>" }) , '</li>');

    The good thing about append is that it takes unlimited amount of parameters, just as if you called it once for every param. And it also accepts array, and handle them correctly.

  • Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download