how display first element loop or each here code foreach?
var slides = ["slide 1", "slide 2", "slide 3", "slide 4", "slide 5"] var str = '' slides.foreach(function(slide) { str += '<li>'+ slide + '</li>'; }); document.getelementbyid("slidelist").innerhtml = str;
<div id="slidelist"></div>
what want strange, yo can't break foreach can pass indexer , check 0 element that:
var slides = ["slide 1", "slide 2", "slide 3", "slide 4", "slide 5"] var str = '' slides.foreach(function(slide, i) { if(i === 0) str += '<li>'+ slide + '</li>'; }); document.getelementbyid("slidelist").innerhtml = str;
<div id="slidelist"></div>
however, sloppy , ilogical , should without loop:
var slides = ["slide 1", "slide 2", "slide 3", "slide 4", "slide 5"] var str = '' str += '<li>'+ slides[0] + '</li>'; document.getelementbyid("slidelist").innerhtml = str;
<div id="slidelist"></div>
Comments
Post a Comment