Search code examples
javascriptarraysobjectjavascript-objects

How to split value in javascript?


Here I have one month object In this month object inside value 1,2,3,4,5 and selected experience value is 04 (see console) so want to find value and I compare both but I got undefined because 4 and 04 not matched How to match them ?

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

Solution

  • What about to convert it into an int?

    console.log(months.find(month => month.value === parseInt(selectedExperience.from.split('/')[0])));