如何在JSON中查找数组中对象的位置

时间:2017-08-21 22:38:00

标签: javascript arrays json node.js indexof

这是我的数据:

xts

我正试图获得{ "bracketName": "Set Bracket Name", "bracketId": "tTzbUZ", "modID": "B11PTVjERm", "creationDate": 1503352813796, "teams": [{ "name": "team 1", }, { "name": "team 2", }, { "name": "team 2", } ] } 的位置。这是我的代码:

team

但它不起作用。我不知道该怎么做。有人能帮助我吗?

2 个答案:

答案 0 :(得分:2)

content.teams.findIndex(team => team.name == 'team 2')

答案 1 :(得分:1)

您可以使用findIndex。例如:

content.teams.findIndex(x => x.name=="team 2")