这里我有一个月的对象在这个月的对象中,值 1,2,3,4,5
并且选择的经验值是 04
(请参阅控制台)所以想要找到值(value),我比较两者,但我得到了未定义,因为 4 和 04 不匹配
如何匹配它们?
console.log(selectedExperience.from.split('/')[0])) // 04
console.log(months) // [ { value : 1, name: "one"}
{ value: 2, name: "two" }
{ value: 4, name: "four" } ]
console.log(months.find(month => month.value === selectedExperience.from.split('/')[0])); // undefined
最佳答案
如何将其转换为 int
?
console.log(months.find(month => month.value === parseInt(selectedExperience.from.split('/')[0])));
关于javascript - 如何在javascript中拆分值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55225411/