Convert javascript array to string

前端 未结 14 927
逝去的感伤
逝去的感伤 2020-11-29 16:41

I\'m trying to iterate over a \"value\" list and convert it into a string. Here is the code:

var blkstr = $.each(value, function(idx2,val2) {                        


        
14条回答
  •  醉话见心
    2020-11-29 17:35

    If value is associative array, such code will work fine:

    var value = { "aaa": "111", "bbb": "222", "ccc": "333" };
    var blkstr = [];
    $.each(value, function(idx2,val2) {                    
      var str = idx2 + ":" + val2;
      blkstr.push(str);
    });
    console.log(blkstr.join(", "));

    (output will appear in the dev console)

    As Felix mentioned, each() is just iterating the array, nothing more.

提交回复
热议问题