Hi I'm new to SASS and want to know how to write something like "if value in array
"
For example:
$animal : dog;
$landAnimal : (dog, cat, lion);
$seaAnimal : (fish, squid, whale);
//keyword IN doesn't work
@if $animal in $landAnimal{
//do something
}@else if $animal in $seaAnimal{
//do something
}
I tried searching the documentation and googling but I haven't found any answers. Anyone here have solution? I believe it is quite simple.
For example, if condition «a» is an array of Booleans (true or false values), it returns an array with the same index, containing «b» or «c» as appropriate: Variable X := -2 .. 2. If X > 0 THEN 'Positive' ELSE IF X < 0 THEN 'Negative' ELSE 'Zero' →
To check if given Array contains a specified element in C programming, iterate over the elements of array, and during each iteration check if this element is equal to the element we are searching for.
The indexof() method in Javascript is one of the most convenient ways to find out whether a value exists in an array or not. The indexof() method works on the phenomenon of index numbers. This method returns the index of the array if found and returns -1 otherwise.
You're looking for the index
function: http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html#index-instance_method
@if index($landAnimal, $animal) {
//do something
} @else if index($seaAnimal, $animal) {
//do something
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With