入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

js 的each()方法遍历对象和数组

创建时间:2015-06-30 投稿人: 浏览次数:24350
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
 <script src="../lib/jquery-1.8.3.min.js" ></script>
<script type="text/javascript" charset="utf-8">

var arr = ["a", "b", "c", "d", "e"];  
var obj = { a: "one", b: "two", c: "three", d: "four", e: "five" };

$.each(obj,function(key,value){
	console.log("Obj :" + key + "-" + value);
})


$.each(arr,function(key,value){
	console.log("arr :" + key + "-" + value);
})
</script>
</body>
</html>


输出结果:

Obj :a-one
Obj :b-two
Obj :c-three
Obj :d-four
Obj :e-five
arr :0-a
arr :1-b
arr :2-c
arr :3-d
arr :4-e

声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。