Display all items in array using jquery

后端 未结 6 1362
悲&欢浪女
悲&欢浪女 2020-12-04 19:07

I have an array that I want to have displayed in html.. I don\'t want to write multiple lines for posting each item in the array but all should be exactly the same. ie

6条回答
  •  甜味超标
    2020-12-04 19:34

    You should use $.map for this:

    var array = ["one", "two", "three"];
    
    var el = $.map(array, function(val, i) {
      return "" + val + "";
    });
    
    $(".element").html(el.join(""));
    

    jsFiddle demo

提交回复
热议问题