[英]Map from-to using react.js
I have a map loop that returns a list of values eg 0 - 100. The problem is that this will return the whole list.我有一个返回值列表的映射循环,例如 0 - 100。问题是这将返回整个列表。 I want to only return a specific number of values.
我只想返回特定数量的值。 eg (11-20).
例如(11-20)。 What would be the best way of implementing this?
实现这个的最好方法是什么?
The current code is目前的代码是
const all = this.props.memories.map((value, index) => {
return (
<div>
{value}
</div>
)
})
Use .slice()
as this.props.memories.slice(11, 20).map...
使用
.slice()
作为this.props.memories.slice(11, 20).map...
Slice..Use it when you do not want to alter the original contents, instead a shallow copy of that for local change and usage. Slice.. 当你不想改变原始内容时使用它,而不是为了本地更改和使用的浅拷贝。
this.props.memories.slice(11,20).map((value, index) => {
return (
<div>{value}</div>
)
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.