M
M
Michael R.2018-06-18 14:16:20
Sass
Michael R., 2018-06-18 14:16:20

SCSS get next element of array?

Greetings!
There is an array:

$arrayColors: (
        white,
        black,
        green,
        red,
        orange
);

I run the loop and get an error
List index is 6 but list is only 5 items long for 'nth'
. I understand that he swears that there are no 6 elements in the array, but how then to get the next elements of the array?
@each $color in $arrayColors {
      $realIndex: index($arrayColors, $color); // настоящий цвет
      $nextIndex: nth($arrayColors, ($realIndex + 1)); // следующий цвет
        .test-#{$realIndex} {
           color: $nextIndex;
        }
      }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sergski, 2018-06-18
@sergski

According to the logic of the code, you take the first position, increment by 1, and access that position in the list. Well, logically, he swears. Why are you doing this, i.e. what css do you need for the output?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question