数组中子字符串的最大值

时间:2018-11-19 13:19:26

标签: javascript arrays lodash

var arr = ["subId":"dfsfsdfsdfSUB201800099","userID":"dfsfsdfsdf"}, {""subId":"dfsfsdfsdfSUB201800139","userID":"dfsfsdfsdf"}, {""subId":"dfsfsdfsdfSUB201700649","userID":"dfsfsdfsdf"} , {}, {}............]

我有一个数组,我想找到subId的值,该值包含“ dfsfsdfsdfSUB2017”,在此示例中为最大值00139。

1 个答案:

答案 0 :(得分:0)

这可能会帮助您:

let someArray = [{
  "subId": "dfsfsdfsdfSUB201800099",
  "userID": "dfsfsdfsdf"
}, {
  "subId": "dfsfsdfsdfSUB201800139",
  "userID": "dfsfsdfsdf"
}, {
  "subId": "dfsfsdfsdfSUB201700649",
  "userID": "dfsfsdfsdf"
}]

let ids = someArray.map(item => parseInt(item.subId.split('dfsfsdfsdfSUB')[1]))

console.log(Math.max(...ids))