I am trying to use a JSON object that holds data in a similar fashion to
const obj = {
key_a : [1, 2, 3, 4, 5],
key_b : [2, 8, 4, 0, 9, 5],
key_c : [1, 2, 3, 4, 5]
}
as you can see key_a and key_c have the same data.
Idealy I would have something like
const obj = {
[key_a, key_c] : [1, 2, 3, 4, 5]
}
or
const obj = {
key_a : [1, 2, 3, 4, 5]
key_c : key_a
}
but offcourse these do not work.
Is there a way to "without merging" make the JSON object more DRY
my Solution at the moment is to use a variable that takes the key and uses a single key as such
input = (input === key_a || input === key_c) ? key_ac : input;
const obj = {
key_ac : [1, 2, 3, 4, 5],
key_b : [2, 8, 4, 0, 9, 5]
}
This feel clumsy and also like there should be a better solution. It also requires changing the key names, which I would also like to avoid.