I'm parsing a CSV with Papaparse, adding a new column of information in the CSV and creating a table with it. I have a method which retrieves the information that I want to add in the CSV and I need to push the return of this method in order to create the table with the new data. The problem is the i can see the returned value with console.log() but when I push this value into an array, nothing happens.
This is the code to parse the CSV and add the new column of data:
fileInput.addEventListener("change", event => {
Papa.parse(fileInput.files[0], {
skipEmptyLines: true,
complete: results => {
const data = results.data.slice(1)
const headers = results.data[0]
headers.push("Endereço")
for (let item of data) {
let itemLat = Number(item[0].split(".").join(""))
let itemLon = Number(item[1].split(".").join(""))
let coordinates = { lat: itemLat, lon: itemLon }
let whereAreWe =
places.places.filter(place => place.isHere(coordinates))
console.log(whereAreWe)
item.push(whereAreWe.toString())
}
tableCsv.update(data, headers)
}
})
})
And this is the method i'm using:
isHere(alertCoordinates = {}) {
const latitude = alertCoordinates.lat
const longitude = alertCoordinates.lon
if (latitude > this.coordinates.botLeft.lat && latitude < this.coordinates.topLeft.lat) {
if (longitude > this.coordinates.botLeft.lon && longitude < this.coordinates.botRight.lon) {
return this.name
}
}
}
I tried to use JSON.stringify, toString(), bracket notation, dot notation, assing the return to a variable before pushing to the array, but nothing works. Sometimes is pushed a black string, sometimes the [object Object].
data.push works with anything except the return of my method.