I'm parsing a string to a float, and when I print the type of the variable, I get number. However, if I add the variable to an array, and print it from there, I get string. But if I then index clicks[0], I once again get number
let clicks = []
let latitude = parseFloat(stringCoords.substring(11, 28))
clicks.push(latitude)
console.log(typeof(latitude)) -- prints number
for (var object in clicks) {
console.log(typeof(object)) -- prints string
}
console.log(typeof(clicks[0])) -- prints number
The only thing I'm adding to the clicks array is the latitude variable. I'm confused as to why it's changing types. Please let me know.
objectis the array index, not the array element.for-ofto loop over array elements.console.log(object)? You would have seen the problem immediately.for...inwhen using Array, which is what you're doing here.