I have an array arrayDescr
and I need to use forEach
to add to every <li>
an attribute data-value
. The value of data-value
should be an arrayDescr
element. For example I have three <li>
's and I have two arrayDescr
elements. Two of three <li>
's should have attribute data-value
arrayDescr[0]
, [1] and etc.
This code works but I need it to work in forEach:
$("#name1").attr("data-value", arrayDescr[0])
#name should be function(){return 'name' (i+1)}.
In forEach this code returns undefined
:
arrayDescr.forEach(function(item, index){
$("li").attr("data-value", item[index])}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…