Answer the question
In order to leave comments, you need to log in
How to compare property values of multiple objects?
have a JSON object
var jsonObject = JSON.parse('<?php echo $JSON_database ?>');
Object {id: "6", hierarchy: "0", login: "John", password: "Gregg"}
Object {id: "7", hierarchy: "0", login: "Hunner", password: "james"}
Answer the question
In order to leave comments, you need to log in
The matter is that I need to implement vsyazka, mysql -> php -> JSON -> JS -> checking -> login;
To carry out all the processing in the data in JS ....
I wonder if it is possible to pull properties from a set of objects for comparison.
For synchronous work with the database.
var arr = [
{id: "6", hierarchy: "0", login: "John", password: "Gregg"},
{id: "7", hierarchy: "0", login: "Hunner", password: "james"}
];
for (var i = 0; i < arr.length; i++) {
if (arr[i].login == loginValue) {
alert('Login found!');
break;
}
}
let arr = [
{"id_request" : "29", "st_name" : "В работе", "h_time" : "103"},
{"id_request" : "29", "st_name" : "В работе", "h_time" : "105"},
{"id_request" : "29", "st_name" : "Закрыта", "h_time" : "117"},
{"id_request" : "29", "st_name" : "Открыта", "h_time" : "101"}
];
let max = arr.reduce((acc, curr) => acc.h_time > curr.h_time ? acc : curr);
console.log(max);
let maxIndex = arr.reduce((acc, curr, i) => arr[acc].h_time > curr.h_time ? acc : i, 0);
console.log(maxIndex);
let max_history = request_history.reduce((acc, curr) => Math.floor(new Date(acc.h_time).getTime() / 1000) > Math.floor(new Date(curr.h_time).getTime() / 1000) ? acc : curr);
arr.sort((a, b) => parseFloat(b.h_time) - parseFloat(a.h_time));
let added_events = ['103', '45', '567'];
let content = arr.filter(function(n) {
return added_events.indexOf(n.h_time) !== -1;
});
console.log(content);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question