吃鸡游戏
根据文档_.indexOf将执行SameValueZero比较来定位索引。简而言之,因为indexOf(data, item)它会尝试使用===to compareitem与data.相反,您可以使用which accepts将被接受的_.findIndex常用简写:_.matchesProperty_.iterateeconst { findIndex } = _;const areaCode = [ { "area_code": 656, "city": "city1" }, { "area_code": 220, "city": "city2" }, { "area_code": 221, "city": "city3" }]const code = 220;let found = findIndex(areaCode, ["area_code", code]);console.log("index:", found);const city = areaCode[found].cityconsole.log("city:", city);<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.20/lodash.min.js"></script>虽然,鉴于您的用法,您可能想要_.findconst { find } = _;const areaCode = [ { "area_code": 656, "city": "city1" }, { "area_code": 220, "city": "city2" }, { "area_code": 221, "city": "city3" }]const code = 220;let found = find(areaCode, ["area_code", code]);console.log("index:", found);const city = found.cityconsole.log("city:", city);<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.20/lodash.min.js"></script>