Answer the question
In order to leave comments, you need to log in
How to scatter the elements of an array over another array?
Hello. There is an array of 4 elements, in my case these are 4 columns from the DOM tree. And there is an array of 12 words. How do I evenly distribute these 12 words across 4 columns, bearing in mind that the number of words may change in the future, but this should not affect the even distribution.
On native js without libraries and other things
Answer the question
In order to leave comments, you need to log in
const words = ['я', 'буду', 'сопровождать', 'свои', 'вопросы', 'на', 'Тостере', 'примерами', 'кода', ',', 'обещаю', '!', ];
const columns = [[], [], [], [],];
words.forEach((word, i) => columns[i % columns.length].push(word));
//
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question