Getting specific value from JSON using javascript

前端 未结 2 1353
孤城傲影
孤城傲影 2021-01-14 13:29

I am using ajax to get a small set of data back from the server which returns JSON data with the following format:

{
    \"data\": [
        {
            \"         


        
2条回答
  •  北恋
    北恋 (楼主)
    2021-01-14 13:55

    You could take a functional approach and use the Array.filter method:

    var matchingResults = JSON['data'].filter(function(x){ return x.id == 2; });
    // procede to use matching elements...
    

提交回复
热议问题