英文:
Karate: How to turn a list of lists into a single list?
问题
我有一个在Karate中的列表列表,看起来像这样:
[[elemtna], [abc], [bcd]]
我想将这个列表转换成一个单一的列表,如下所示:[elemtna, abc, bcd]
我尝试了以下代码,但没有成功:
- def mylist = existingList.map(x => x.map(y => String(y)))
英文:
I have a list of lists in Karate that looks like:
[[elemtna], [abc], [bcd]]
I'd like to convert this list into a single list like: [elemtna, abc, bcd]
I tried the following code with no success:
- def mylist = existingList.map(x => x.map(y => String(y)))
答案1
得分: 2
你可以使用flat()
方法:
[['elemtna', 'doc', 'third'], ['abc'], ['bcd']].flat() // 返回 ['elemtna', 'doc', 'third', 'abc', 'bcd']
英文:
You can use the flat()
method:
[['elemtna', 'doc', 'third'], ['abc'], ['bcd']].flat() // returns ['elemtna', 'doc', 'third', 'abc', 'bcd']
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论