Javascript 使用其他对象作为参数筛选对象数组

Javascript 使用其他对象作为参数筛选对象数组,javascript,ecmascript-6,filtering,Javascript,Ecmascript 6,Filtering,我想过滤每个国家的JSON数据属性名称,以便在网站上进行“搜索” let array = { continents: [ { name: "Europe", countries: [ { name: "Austria", adresses: { 1: "one", 2: "two", 3: "three" }

我想过滤每个国家的JSON数据属性名称,以便在网站上进行“搜索”

let array = {
    continents: [
    {
      name: "Europe",
      countries: [
        {
          name: "Austria",
          adresses: {
            1: "one",
            2: "two",
            3: "three"
          }
        },
        {
          name: "Germany",
          adresses: {
            1: "one",
            2: "two",
            3: "three"
          }
        }
      ]
    },
    {
      name: "Asia",
      countries: [
        {
          name: "Thailand",
          adresses: {
            1: "one",
            2: "two",
            3: "three"
          }
        },
        {
          name: "Japan",
          adresses: {
            1: "one",
            2: "two",
            3: "three"
          }
        }
      ]
    }
  ]
};
预期的行为是,当我键入“an”时,结果将是如下所示的数组:

let array = {
    continents: [
    {
      name: "Europe",
      countries: [
        {
          name: "Germany",
          adresses: {
            1: "one",
            2: "two",
            3: "three"
          }
        }
      ]
    },
    {
      name: "Asia",
      countries: [
        {
          name: "Thailand",
          adresses: {
            1: "one",
            2: "two",
            3: "three"
          }
        },
        {
          name: "Japan",
          adresses: {
            1: "one",
            2: "two",
            3: "three"
          }
        }
      ]
    }
  ]
};
这样我们就可以摆脱奥地利了

如何做到这一点?我们是否应该使用fliter函数(基准测试表明它的速度很慢,基于:)。我们也可以搜索大陆名称吗

现在我知道如何记录正确的值,但如何从中组成正确的数组?
let数组={
大陆:[
{
名称:“欧洲”,
国家:[
{
名称:“奥地利”,
地址:{
1:"一",,
二:"两个",,
3:“三”
}
},
{
名称:“德国”,
地址:{
1:"一",,
二:"两个",,
3:“三”
}
}
]
},
{
名称:“亚洲”,
国家:[
{
名称:“泰国”,
地址:{
1:"一",,
二:"两个",,
3:“三”
}
},
{
名称:“日本”,
地址:{
1:"一",,
二:"两个",,
3:“三”
}
}
]
}
]
};
searchValue=“an”;
for(设i=0;i}
好吧。。创建空数组,并在符合搜索条件时推送国家/地区名称:

const数组={
大陆:[{
名称:“欧洲”,
国家:[{
名称:“奥地利”,
地址:{
1:"一",,
二:"两个",,
3:“三”
}
},
{
名称:“德国”,
地址:{
1:"一",,
二:"两个",,
3:“三”
}
}
]
},
{
名称:“亚洲”,
国家:[{
名称:“泰国”,
地址:{
1:"一",,
二:"两个",,
3:“三”
}
},
{
名称:“日本”,
地址:{
1:"一",,
二:"两个",,
3:“三”
}
}
]
}
]
}
const searchValue=“an”
让结果=[]
array.continents.forEach(e=>
e、 countries.forEach(v=>
v、 name.toLowerCase().includes(searchValue)和&result.push(v.name))
)

console.log(result)
如果需要调试帮助,请向我们显示您迄今为止尝试过的代码。速度很少是一个重要的问题;您可能会先得到一些有效的方法,然后再考虑如何加快速度。如果我们使用flitter函数(基准测试表明它很慢),proof please
JSON
对于变量名来说不是一个很好的选择。@CertainPerformance poor snippet Added参考基准测试,除非你有一个数万或数十万个项目的庞大列表,否则你不会看到有什么不同。此外,它在Firefox中的速度也一样快,但在Chrome中要慢一点。我仍然不会让它决定你选择的解决方案。仅仅因为它比其他东西“慢”并不意味着它“慢”。这样我将失去大陆阵列