Reputation: 475
I try to wrap each array item inside a <li></li>
and save into a variable.
After that insert a <ul>
at the beginning and a </ul>
at the end.
What I've got so far:
$("document").ready(function() {
var array = ["one", "two", "three", "four", "five"];
jQuery.each(array, function(index, value) {
value[index].wrap("<li></li>");
var listItems = value[index].join("\n");
});
});
But I get this error:
value[index].wrap is not a function
Upvotes: 1
Views: 1008
Reputation: 103
Updated your fiddle: https://jsfiddle.net/vkq3hnzu/2/
var array = ["one", "two", "three", "four", "five"],
ul = $('<ul>');
jQuery.each(array, function(index, value) {
$('<li>').text(value).appendTo(ul);
});
ul.appendTo('body');
Upvotes: 2