for(var b in this)这个里的b是一个in后面这个对象所包含的属性(或成员,或变量),是一String,当然这里是程序里所涉及到的动态属性,而
for each(var b in this)这个里的b,你要知道b是什么?b是一个Object类型.
例如:
1 var myObj:Object = {x:20, y:30};
2 for (var i:String in myObj) {
3 trace (i + ": " + myObj[i]);
4 }
5 // output:
6 // x: 20
7 // y: 30
由上代码可知道for..in是把
数组的元素或对象的属性名依次取过来。
1 var myObj:Object = {x:20, y:30};
2 for each(var num in myObj) {
3 trace (num);
4 }
5 // output:
6 // 20
7 // 30
由上代码可知道for each..in是把
对象的属性名对应的值依次取过来。
1 var myArray:Array = ["one", "two", "three"];
2 for (var i:String in myArray) {
3 trace (myArray[i]);
4 }
5 /* output
6 one
7 two
8 three
9 */
10
如果用for each..in返回将是undefined。
对于XML文档:
1 var myXML:XML = <users>
2 <fname>Jane</fname>
3 <fname>Susan</fname>
4 <fname>John</fname>
5 </users>;
6 for (var item in myXML.fname) {
7 trace(item);
8 }
9 /* output
10 0
11 1
12 2
13 */
14
如果用for each..in返回的将是:
1 /* output
2 Jane
3 Susan
4 John
5 */
6
分享到:
相关推荐
在编程语言中,遍历数组或集合是常见的操作,JavaScript 和 ActionScript 提供了两种不同的循环语法:`for...in` 和 `for each...in`。这篇文章主要探讨了从数据结构角度分析这两种循环方式的效率差异。 首先,`for...
MVVM Survival Guide for Enterprise Architectures in Silverlight and WPF will help you to choose the best MVVM approach for your project while giving you the tools, techniques, and confidence that you ...
This book covers Android app design fundamentals in Android Studio using Java programming language. The author assumes you have no experience in app development. The book starts with the installation ...
The R language is widely used by statisticians for data analysis, and the popularity of R programming has therefore increased substantially in recent years. The emerging Internet of Things (IoT) ...
It provides a thorough examination of the basics, covering each subject in fine detail. Great care has been taken to advance through the subject matter in an order that best ensures that everything ...
在JavaScript和ActionScript等编程语言中,`for...in`循环和`for each...in`循环是用来遍历对象属性的两种不同方式。然而,在特定情况下,`for each...in`循环可能比`for...in`循环更为高效。这篇文章将深入探讨这两...
Dundas Chart for .NET is the industry leader in .NET Charting Solutions. Providing you with the most comprehensive features, the most complete sample framework, and the best live technical support ...
For Each element In collection ' 代码块,处理当前元素 Next element ``` 这里的`element`是循环变量,`collection`是你要遍历的对象,可以是数组或者任何实现了`IEnumerable`接口的集合。 **一、遍历数组** ...
Scaling applications: assign services to specific teams, label the criticalness of each service, and devise failure scenarios and recovery plans Cloud services: understand the structure of cloud-based...
Packed with tips and tricks on how to make the most of each app, this book escorts you through a vast selection of apps and then helps you narrow down the most essential and most entertaining apps for...
Towards the end, you will be introduced to some best practices to secure your containers and COE on OpenStack, with an overview of using each OpenStack projects for different use cases. Table of ...