0
 comment =[   {
            "id": 4,
            "snippetId": 1,
            "text": "This code is correct but looks verbose. May be replace this hashset with an array so you can statically initialize?",
            "line": 30,
            "published_date": "2019-08-14T18:15:05.360241Z"
        },
        {
            "id": 11,
            "snippetId": 6,
            "text": "On first glance, the code seems to be fine. But it assumes that first two numbers are each single-digit numbers. I think you should attempt to modify this method to include the more general case where first two numbers are multiple digits.",
            "line": 4,
            "published_date": "2019-08-15T00:36:55Z"
        },
        {
            "id": 12,
            "snippetId": 6,
            "text": "indentation is off. Some interviewers may not like this.",
            "line": 36,
            "published_date": "2019-08-15T00:40:25.296813Z"
        }

]

//这是我的json //请帮助如何过滤具有snippetId = 6的对象(r​​eact js)

4

1 回答 1

-1

不过,您还应该多研究一下 json 是什么以及如何在 javascript 中使用数组。

JSON.parse(comment).find(item => item.snippetId == 6)

comment = `[{
    "id": 4,
    "snippetId": 1,
    "text": "This code is correct but looks verbose. May be replace this hashset with an array so you can statically initialize?",
    "line": 30,
    "published_date": "2019-08-14T18:15:05.360241Z"
  },
  {
    "id": 11,
    "snippetId": 6,
    "text": "On first glance, the code seems to be fine. But it assumes that first two numbers are each single-digit numbers. I think you should attempt to modify this method to include the more general case where first two numbers are multiple digits.",
    "line": 4,
    "published_date": "2019-08-15T00:36:55Z"
  },
  {
    "id": 12,
    "snippetId": 6,
    "text": "indentation is off. Some interviewers may not like this.",
    "line": 36,
    "published_date": "2019-08-15T00:40:25.296813Z"
  }
]`;

console.log(JSON.parse(comment).find(item => item.snippetId == 6));

于 2020-06-14T07:21:12.763 回答