I
I
Ivan2021-07-15 00:01:17
React
Ivan, 2021-07-15 00:01:17

How to set a certain repeating sequence of styles for array elements?

Hello.
There is an array of unknown length with objects. Depending on the value of the "id" of the object, you need to set the shape of the element in the following sequence:
- square
- circle
- arch
- circle
- arch
- square
- arch
- square
- circle
- then repeat

There was an idea to split the array into subarrays with the number of elements in length sequence, and then each independently assign a form, no more thoughts .. Tell me how to do it right

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-07-15
@Mjogan

If by "Depending on the value of "id"" it is meant that there is a serial number in id, then so (otherwise - extrapolate yourself):

const types = ['квадрат', ...];
// ...
const type = types[obj.id % types.length];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question