我想遍历一个字符串,我想在这个索引处同时拥有索引和字符。我知道我可以为此使用一个简单的 for 循环,但我认为 Javascript/Typescript 的一些新功能可能更优雅,所以我尝试了这个:
for (const [i, character] of Object.entries('Hello Stackoverflow')) {
console.log(i);
console.log(typeof(i));
console.log(character);
}
Run Code Online (Sandbox Code Playgroud)
令人惊讶的是,这有效,但是即使i计数,它也是一个字符串。因此,例如这不起作用:
'other string'.charAt(i)
Run Code Online (Sandbox Code Playgroud)
我是 Typescript 的新手,所以我的问题是:
如何将 a 的最后两项RecyclerView与 3 列居中?
包含 5 个项目的示例:
1 item | 2 item | 3 item
4 item | 5 item
Run Code Online (Sandbox Code Playgroud)