对象"/>
比较NodeJS中的JSON对象
您如何在NodeJS中读取和比较JSON数据?
{
"currentcount": 150,
"hasStorm": false,
"players": [
{
"world": "earth",
"armor": 0,
"name": "ceduuu",
"x": 5400.0,
"y": 115.0,
"health": 0,
"z": -11309.0,
"sort": 1,
"type": "player",
"account": "ceduuu"
},
{
"world": "-some-other-bogus-world-",
"armor": 0,
"name": "Egga_",
"x": 0.0,
"y": 64.0,
"health": 0,
"z": 0.0,
"sort": 1,
"type": "player",
"account": "Egga_"
},
有150个单独的数据,我想将X,Z和帐户暂时存储在变量中,以便我进行比较。但是,我将如何准确地检查第一个玩家的数据以及我将如何检查秒数玩家的数据?
回答如下:尚不清楚您想将对象与之进行比较,但是这里有一些代码可以帮助您入门。
const comparePlayers = (players) => {
// iterates over each object
players.forEach(player => {
// destructure object
const { x, z, account } = player;
// your compare players logic
});
};
comparePlayers(jsonData.players);
更多推荐
比较NodeJS中的JSON对象
发布评论