1
I’m trying to create a top menu piece with Ecmascript instead of pure html, but I’m not getting what’s left to add the element.
Code HTML
<div class="rd-navbar-cell rd-navbar-nav-wrap" id="list">
<ul class="rd-navbar-nav rd-navbar-nav-default">
<!-- Queria que os elementos que estão no Array vão parar aqui -->
</ul>
</div>
Code Ecmascript:
var listElement = document.querySelector("#list ul")
var listsElement = ['Home',
'Cursos',
'Promoções',
'Eventos',
'Blog',
'Quem-somos',
'Soluções Corporativas',
'Parceiros'
]
var x = listsElement.map(function(item){
return item;
})
listElement.createElement('li')
listElement.appendChild(x)
I feel like I’m missing something to add or I’m wrong... Could someone explain to me?
Opa @Sergio thanks for the reply, I thought that
.map
had the same effect as aforeach.
– user152996
@Rodrigopires more or less... semantically are different, the
.map
is to create a new array. But in practice both traverse the array.– Sergio