How can I find data related to already known data? (I'm a newbie.)
For example, here is my json:
[
{ "id": "1", "log": "1","pass": "1111" },
{ "id": 2, "log": "2","pass": "2222" },
{ "id": 3, "log": "3","pass": "3333" }
]
Now I know what "log"is 1, and I want to know the data associated with it "pass".
I tried to do it like this:
The POST request comes with data logand pass, I am looking at the .json file for the same value log, and if there is the same data, then I look for the appropriatepass
fs.readFile("file.json", "utf8", function (err, data) {
var jsonFileArr = [];
jsonFileArr = JSON.parse(data);
var log = loginData.log;
var gibtLog = jsonFileArr.some(function (obj) {
return obj.log == log;
});
if (gotLog) {
var pass = loginData.pass;
var gotPass = jsonFileArr.some(function (obj) {
return obj.pass == pass;
});
}
else
console.log("error");
});
The problem is that when I use
var gotPass = jsonFileArr.some(function (obj) {
return obj.pass == pass;
});
it scans the entire .json file, not just through the objekt object.
source
share