Как можно вывести 2 случайных элемента массива?
export const ratingScreen = app.screen('/rating', async (ctx, req) => {
let records = await ImagesTable.findAll(ctx, {
where:{
sessionId: ctx.session.id
}
});
return (
<screen title="Rating picture">
<box style={{ flexDirection: 'row' }}>
{records.map((record, index) => {
if (index < 2) {
return (
<box key={index} style={{ flex: 1, padding: 6, backgroundColor: 'lightblue', marginHorizontal: 4, marginTop: 6 }}>
<list-item
style={{height: '100%', width: '100%'}}
icon={{url: record.image.getThumbnailUrl(100)}}
content={{
title: record.filename,
subTitle: record.createdAt.toLocaleDateString(),
}}
/>
</box>
)
}
}
)}
</box>
</screen>
)
});
Пока что у меня получается вывести только 2 первых элемента. Также в (index < 2) я пробовал (index < Math.floor(Math.random() * array.length)), но так отрисовывается разное количество элементов.