B
B
bingumd2018-01-30 20:08:45
css
bingumd, 2018-01-30 20:08:45

How to correctly remove values ​​from an array in Stylus?

There is this piece of code:

$colors = {
    'primary'   : #124af5
    'dark'        : #222222
    'white'      : #ffffff
}

Then I copy $colors to $colors-2 and remove one value from it:
$colors-2 = $colors
remove($colors-2, 'primary')

Everything works, but is removed from all variables.
How to remove values ​​only from the second variable?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sn4il, 2018-01-30
@bingumd

The problem is that after the line, $colors-2 = $colorsboth variables point to the same hash (array). Instead of this line, you need to write $colors-2 = merge({}, $colors)to copy the contents $colorsinto $colors-2, and then it $colors-2will already point to a copy, and not to the same hash. Something like this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question