Get index of current item in a PowerShell loop

前端 未结 5 1999
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-24 00:19

Given a list of items in PowerShell, how do I find the index of the current item from within a loop?

For example:

$letters = { \'A\', \'B\', \'C\' }
         


        
5条回答
  •  执笔经年
    2020-12-24 01:03

    For PowerShell 3.0 and later, there is one built in :)

    foreach ($item in $array) {
        $array.IndexOf($item)
    }
    

提交回复
热议问题