Selecting json values with jQuery

前端 未结 2 856
南笙
南笙 2021-01-27 08:27

I have a json object as follows:

[{\"Id\":\"1\",\"Item\":\"Apples\",\"PricePerKilo\":\"10.00\"},
 {\"Id\":\"3\",\"Item\":\"Oranges\",\"PricePerKilo\":\"12.00\"}]         


        
2条回答
  •  面向向阳花
    2021-01-27 08:47

    You would have to loop through your array and select the id that matches:

    $.each(fruits, function(i, val){
        if (val.Id == 3) {
            // val is now the single fruit object with the id of 3
        }
    });
    

提交回复
热议问题