How to avoid undefined in string concatenation?

后端 未结 2 2136
无人共我
无人共我 2021-01-18 23:17

I\'m iterating over an object and I want to concatenate the name of the service. This is my code:

var servizi;

for(var i = 0; i < appointment.id_services         


        
相关标签:
2条回答
  • 2021-01-19 00:02

    You get undefined because you declared an uninitialized variable, and then added to it (twice).

    Initialize the declared variable as an empty string first

    var servizi = "";
    
    0 讨论(0)
  • 2021-01-19 00:07

    intialize variable to empty string

    var servizi = "";
    
    0 讨论(0)
提交回复
热议问题