0

I would like to explain my problem of the day.

currently i have an json

const translations = [{
  "fr": {
    "A.A.B_B": "salut",
    "example": "example",
  },
  "en": {
    "A.A.B_B": "Hi",
    "example": "example",
  },
}]

// then I map
const lg = "fr";
const filterLg = translations.map((e) => e[lg]);

// then I reduce for to delete the table

const t = filterLg.reduce(
  (accumulator, value) => ({ ...accumulator, value }), {}
);

console.log(t)

this works correctly.

my problem and the next one

this does not work

   console.log(t.value.A.A.B_B);

but this yes

console.log(t.value.example);

iam open to any proposal thank you very much.

thx Neff

adiga
  • 34,372
  • 9
  • 61
  • 83
Neff
  • 199
  • 2
  • 17
  • 3
    It has one key, `"A.A.B_B"`, so `console.log(t.value["A.A.B_B"])` would work. `t.value.A.A.B_B` tries to access the key `A`, with a sub-key `A` with another sub-key `B_B`. – super Jul 28 '22 at 08:52
  • Also, if there are multiple objects in `translations`, the code `({ ...accumulator, value })` will only keep the last object from the array. – adiga Jul 28 '22 at 08:54

0 Answers0