for in和for each遍历的区别

    xiaoxiao2021-04-15  272

    var dataSource:Object = {}; dataSource[1] = 1000; dataSource[2] = 2000; dataSource[3] = 3000; dataSource[4] = 4000; console.log("for each遍历"); for each(var value:int in dataSource){ console.log("for each"+"-"+value); } console.log("for in遍历"); for (var key:int in dataSource){ console.log("for in"+"-"+key); }

    根据代跑跑出来的结果可以发现,for each遍历的是dataSource中的每一项value

    for in 遍历的是dataSource中每一项的key值


    最新回复(0)