我想搜索一個 JSON 文件,看看它是否包含我要搜索的電子郵件地址(下面代碼中的 example@mail.com)。但是,它不起作用。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", "example@mail.com")) { console.log("LOGGED IN")}JSON:[ { "email": "example@mail.com" }, { "email": "mail@example.com" }]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": "example@mail.com" }, { "email": "mail@example.com" }];if(contains(fullEmailRecord, "email", "example@mail.com")) { console.log("LOGGED IN")}
檢查json是否包含key
月關寶盒
2023-04-14 17:31:41