如何使用每个迭代器获取数组索引或迭代号? [英] How to get the array index or iteration number with an each iterator?

查看:14
本文介绍了如何使用每个迭代器获取数组索引或迭代号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遍历每个 ruby​​ 中的数组.有没有一种简单的方法可以在不返回 for 循环的情况下获取迭代次数或数组索引?

I'm iterating through an array in ruby with each. Is there an easy way to get the iteration number or array index without going back to a for loop?

推荐答案

啊,明白了.

each_with_index

哇!

哎呀!

这篇关于如何使用每个迭代器获取数组索引或迭代号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆