小编kal*_*lin的帖子

过滤嵌套的 JSON javascript

我正在创建一个采用这样的 JSON 的 API:

 "hightlights":[
  {
     "title":"Fun",
     "url":"fun/index.html",
     "queries":
     [
        "music",
        "artists",
        "events",
        "internet"
     ]
  },
  {
     "title":"Internet",
     "url":"internet/index.html",
     "queries":
     [
        "javascript",
        "web",
        "internet",
     ]
  }
 ] 
Run Code Online (Sandbox Code Playgroud)

我需要使用用户给出的单词过滤 JSON,并返回另一个 JSON,其中只有包含“查询”中的单词的对象。

 If word === 'music', receive:
 {
     "title":"Fun",
     "url":"fun/index.html",
     "queries":[
        "music",
        "artists",
        "events",
        "internet"
     ]
 }

 If word === 'internet', receive:
 {
     {
     "title":"Fun",
     "url":"fun/index.html",
     "queries":[
        "music",
        "artists",
        "events",
        "internet"
     ]
  },
  {
     "title":"Internet",
     "url":"internet/index.html",
     "queries":[
        "javascript",
        "web",
        "internet",
     ]
  }
Run Code Online (Sandbox Code Playgroud)

我的问题是如何嵌套这个值?如果有人能给我一些例子......我会很感激......

javascript api json filter

2
推荐指数
1
解决办法
5790
查看次数

标签 统计

api ×1

filter ×1

javascript ×1

json ×1