[英]display the values as per the priority in reactjs
I have two array of Objects,array1 and array2.我有两个对象数组,array1 和 array2。 I can only show three values from both the arrays but priority is given to the array1.
我只能显示两个数组中的三个值,但优先级被赋予了 array1。 Requirement is, if array1 contains 3 elements, then show all the three elements.
要求是,如果 array1 包含 3 个元素,则显示所有三个元素。 If array1 contain 2 elements then show 2 elements from array1 and 1 element from array2.
如果 array1 包含 2 个元素,则显示 array1 中的 2 个元素和 array2 中的 1 个元素。 If array1 contain contains 1 elements, then show rest 2 elements from array2.
如果 array1 包含 1 个元素,则显示 array2 中的其余 2 个元素。 I am not sure how to put this logic in my react code.
我不确定如何将此逻辑放入我的反应代码中。 Right now, I am simply printing all the values.
现在,我只是打印所有值。 Any help would be highly appreciated.
任何帮助将不胜感激。
{arrayOne.map((data) => (
<ListOfValues
data={product.details}
></ListOfValues>
))}
{arrayTwo.map((data) => (
<ListOfValues
data={product.details}
></ListOfValues>
))}
Try尝试
{arrayOne.concat(arrayTwo).slice(0, 3).map((data) => (
<ListOfValues
data={product.details}
></ListOfValues>
))}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.