我想搜索一個 JSON 文件,看看它是否包含我要搜索的電子郵件地址(下面代碼中的 [email protected])。但是,它不起作用。function contains(arr, key, val) { for (var i = 0; i < arr.length; i++) { if(arr[i][key] === val) return true; } return false;}emailRecord = JSON.parse(req.responseText); //Got this from an XMLHttpRequest.if(contains(fullEmailRecord, "email", "[email protected]")) { console.log("LOGGED IN")}JSON:[ { "email": "[email protected]" }, { "email": "[email protected]" }]function contains(arr, key, val) { for (var i = 0; i < arr.length; i++) { if(arr[i][key] === val) return true; } return false;}const fullEmailRecord = [ { "email": "[email protected]" }, { "email": "[email protected]" }];if(contains(fullEmailRecord, "email", "[email protected]")) { console.log("LOGGED IN")}
檢查json是否包含key
月關寶盒
2023-04-14 17:31:41