I have an array with various objects and I am trying to find all objects that have the string "en-GB". However, I am encountering an issue with my current approach that gives me the error message "Cannot use 'in' operator to search for 'en' in en-GB".
Array:
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",
},
},
},
],
];
JavaScript filter:
const res = filtData.map((el) => el.filter((a) => a.descriptions.attrs.lang.includes("en-GB")));
console.log(filtData);