Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
            
                    
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        6年前关闭。
                    
                
        

假设我有一个像这样的json数组:

var data = {
    "cars": [
        {
            "id": 2,
            "name": "Porsche",
            "number": "A00.0"
        },
        {
            "id": 3,
            "name": "Audi",
            "number": "A00.1"
        }
    ]
}


现在,我想检查我的var Carnumber = A00.1是否包含在data['cars'].number数组中。

我是编程的初学者,并尝试过这样的操作:

$.map(data['cars'], function (field, i) {
    if(field.nummer == CarNumber){
        $('p').html(field.id);
    };
});


第一个问题是它似乎不起作用:http://jsfiddle.net/wA9kj/

其次,如果我选择的方法确实是最快的,那对我来说会很有趣吗?
谢谢!

最佳答案

if(field.number == CarNumber){不是if(field.nummer == CarNumber){

10-05 20:54