Tengo la siguiente matriz a continuación y busco hacer coincidir todos los objetos que coinciden con la cadena "en-GB". Mi implementación actual da como resultado "No se puede usar el operador 'in' para buscar 'en' en en-GB"
Formación:
const filtData = [ [ { descriptions: { attrs: { lang: "en-GB", }, }, }, { descriptions: { attrs: { lang: "es", }, }, }, { descriptions: { attrs: { lang: "dk", }, }, }, ], [ { descriptions: { attrs: { lang: "sp", }, }, }, { descriptions: { attrs: { lang: "en-GB", }, }, }, { descriptions: { attrs: { lang: "it", }, }, }, ], [ { descriptions: { attrs: { lang: "en", }, }, }, { descriptions: { attrs: { lang: "uk", }, }, }, { descriptions: { attrs: { lang: "en-GB", }, }, }, ], ];Filtro JS:
const res = filtData.map((el) => el.filter((a) => a.descriptions.attrs.lang.some((o) => "en-GB" in o))); console.log(filtData);Necesitas comparar el valor.
const filtData = [[{ descriptions: { attrs: { lang: "en-GB" } } }, { descriptions: { attrs: { lang: "es" } } }, { descriptions: { attrs: { lang: "dk" } } }], [ { descriptions: { attrs: { lang: "sp" } } }, { descriptions: { attrs: { lang: "en-GB" } } }, { descriptions: { attrs: { lang: "it" } } }], [{ descriptions: { attrs: { lang: "en" } } }, { descriptions: { attrs: { lang: "uk" } } }, { descriptions: { attrs: { lang: "en-GB" } } }]], result = filtData.map(a => a.filter(({ descriptions: { attrs: { lang } } }) => lang === "en-GB") ); console.log(result); .as-console-wrapper { max-height: 100% !important; top: 0; }