M8Test Help

onEachIndexed

val words = arrayOf("hello", "world", "kotlin") // 打印每个单词及其索引,并返回原始数组 val result = words.onEachIndexed { index, word -> _console.log("Index: ", index, "Word: ", word) } // 输出:结果: [Ljava.lang.String;@... _console.log("结果: ", result) // 同时打印: // 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")) // 打印每个单词及其索引,并返回原始数组 def result = words.onEachIndexed { index, word -> $console.log("Index: ", index, "Word: ", word) } // 输出:结果: [Ljava.lang.String;@... $console.log("结果: ", result) // 同时打印: // 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")) // 打印每个单词及其索引,并返回原始数组 let result = words.onEachIndexed((index, word) => { $console.log("Index: ", index, "Word: ", word) }) // 输出:结果: [Ljava.lang.String;@... $console.log("结果: ", result) // 同时打印: // 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")) -- 打印每个单词及其索引,并返回原始数组 local result = words:onEachIndexed(function(index, word) _console:log("Index: ", index, "Word: ", word) end) -- 输出:结果: [Ljava.lang.String;@::: _console:log("结果: ", result) -- 同时打印: -- 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")); // 打印每个单词及其索引,并返回原始数组 $result = $words->onEachIndexed(function ($index, $word) use ($console) { $console->log("Index: ", $index, "Word: ", $word); }); // 输出:结果: [Ljava.lang.String;@::: $console->log("结果: ", $result); // 同时打印: // 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")) # 打印每个单词及其索引,并返回原始数组 result = words.onEachIndexed(lambda index, word: _console.log("Index: ", index, "Word: ", word)) # 输出:结果: [Ljava.lang.String;@... _console.log("结果: ", result) # 同时打印: # 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")) # 打印每个单词及其索引,并返回原始数组 result = words.onEachIndexed { |index, word| $console.log("Index: ", index, "Word: ", word) } # 输出:结果: [Ljava.lang.String;@... $console.log("结果: ", result) # 同时打印: # Index: 0, Word: hello # Index: 1, Word: world # Index: 2, Word: kotlin
Last modified: 09 September 2025