how to create a list of span for a given array

后端 未结 3 535
灰色年华
灰色年华 2021-01-21 08:58

Let\'s say I have an object which looks like that:

var users = [\'user1\', \'user2\'];

For this object I would like to create a list of span li

3条回答
  •  滥情空心
    2021-01-21 09:40

    Assuming users should contain strings only, try this:

    var users = ['user1', 'user2'];
    for (var i = 0; i < users.length; i++) {
        $("").text(users[i]).appendTo("body");
    };
    

    Example fiddle

提交回复
热议问题