M8Test Help

withIndex

val words = arrayOf("hello", "world", "kotlin") // 迭代数组元素及其索引 words.withIndex().forEach { _console.log("Index: ", it.index, "Word: ", it.value) } // 输出: // Index: 0, Word: hello // Index: 1, Word: world // Index: 2, Word: kotlin
def words = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "hello", "world", "kotlin")) // 迭代数组元素及其索引 words.withIndex().forEach { $console.log("Index: ", it.index, "Word: ", it.value) } // 输出: // Index: 0, Word: hello // Index: 1, Word: world // Index: 2, Word: kotlin
let words = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "hello", "world", "kotlin")) // 迭代数组元素及其索引 words.withIndex().forEach((it) => { $console.log("Index: ", it.index, "Word: ", it.value) }) // 输出: // Index: 0, Word: hello // Index: 1, Word: world // Index: 2, Word: kotlin
local words = _objectWrappers:wrap(_arrays:arrayOf(_plugins:loadClass("java.lang.String"), "hello", "world", "kotlin")) -- 迭代数组元素及其索引 words:withIndex():forEach(function(it) _console:log("Index: ", it.index, "Word: ", it.value) end) -- 输出: -- Index: 0, Word: hello -- Index: 1, Word: world -- Index: 2, Word: kotlin
<?php $words = $objectWrappers->wrap($arrays->arrayOf($plugins->loadClass("java.lang.String"), "hello", "world", "kotlin")); // 迭代数组元素及其索引 $words->withIndex()->forEach(function ($it) use ($console) { $console->log("Index: ", $it->index, "Word: ", $it->value); }); // 输出: // Index: 0, Word: hello // Index: 1, Word: world // Index: 2, Word: kotlin
words = _objectWrappers.wrap(_arrays.arrayOf(_plugins.loadClass("java.lang.String"), "hello", "world", "kotlin")) # 迭代数组元素及其索引 words.withIndex().forEach(lambda it: _console.log("Index: ", it.getIndex(), "Word: ", it.getValue())) # 输出: # Index: 0, Word: hello # Index: 1, Word: world # Index: 2, Word: kotlin
# encoding: utf-8 words = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "hello", "world", "kotlin")) # 迭代数组元素及其索引 words.withIndex().forEach { |it| $console.log("Index: ", it.index, "Word: ", it.value) } # 输出: # Index: 0, Word: hello # Index: 1, Word: world # Index: 2, Word: kotlin
Last modified: 29 April 2025