开发者

js equiv of php's foreach($arr as $k=>$v)

开发者 https://www.devze.com 2023-01-17 22:05 出处:网络
Lets be clear, I\'m not asking for for(var i in list) I want the key assigned to a vari开发者_JS百科able as well.The key is, actually, the only thing that gets assigned:

Lets be clear, I'm not asking for for(var i in list) I want the key assigned to a vari开发者_JS百科able as well.


The key is, actually, the only thing that gets assigned:

var value;
for(var key in list) {
    value = list[key];
    // do something with key, value
}


Javascript doesn't have this functionality built into the language. The closest it comes is the for (...in...) syntax that you've already rejected.

Look to your javascript library for this functionality. For example, the ever ubiquitous jQuery's each().

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号