M8Test Help

mapIndexed

val words = arrayOf("hello", "world", "kotlin") // 将每个单词转换为带索引的字符串, 带索引的单词: [0: hello, 1: world, 2: kotlin] words.mapIndexed { index, word -> "$index" + ": " + word }.forEach { _console.log(it) }
def words = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "hello", "world", "kotlin")) // 将每个单词转换为带索引的字符串, 带索引的单词: [0: hello, 1: world, 2: kotlin] words.mapIndexed { index, word -> index + ": " + word }.forEach { $console.log(it) }
let words = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "hello", "world", "kotlin")) // 将每个单词转换为带索引的字符串, 带索引的单词: [0: hello, 1: world, 2: kotlin] words.mapIndexed((index, word) => index + ": " + word).forEach((it) => { $console.log(it) })
local words = _objectWrappers:wrap(_arrays:arrayOf(_plugins:loadClass("java.lang.String"), "hello", "world", "kotlin")) -- 将每个单词转换为带索引的字符串, 带索引的单词: [0: hello, 1: world, 2: kotlin] words:mapIndexed(function(index, word) return index .. ": " .. word end) :forEach(function(it) _console:log(it) end)
<?php $words = $objectWrappers->wrap($arrays->arrayOf($plugins->loadClass("java.lang.String"), "hello", "world", "kotlin")); // 将每个单词转换为带索引的字符串, 带索引的单词: [0: hello, 1: world, 2: kotlin] $words->mapIndexed(function ($index, $word) { return $index . ": " . $word; })->forEach(function ($it) use ($console) { $console->log($it); });
words = _objectWrappers.wrap(_arrays.arrayOf(_plugins.loadClass("java.lang.String"), "hello", "world", "kotlin")) # 将每个单词转换为带索引的字符串, 带索引的单词: [0: hello, 1: world, 2: kotlin] words.mapIndexed(lambda index, word: str(index) + ": " + word).forEach(lambda it: _console.log(it))
# encoding: utf-8 words = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "hello", "world", "kotlin")) # 将每个单词转换为带索引的字符串, 带索引的单词: [0: hello, 1: world, 2: kotlin] words.mapIndexed { |index, word| index.to_s + ": " + word }.forEach { |it| $console.log(it) }
Last modified: 09 September 2025