I load the csv file. This file is loaded as one long string. I divide this string into rows (row). Then I want to split each line into an object and add an object (jsonConvert). However, when I try to add a new row as an object I get a message:
Error in v-on handler: "TypeError: this.jsonConvert.push is not a function".
<script>
export default {
data() {
return {
csvData: "",
jsonConvert: {},
renderTable: false,
uniqueCategory: [],
};
},
methods: {
onFileChange(e) {
let files = e.target.files[0];
let reader = new FileReader();
reader.onload = (e) => (this.csvData = e.target.result.split("\n"));
reader.readAsText(files);
},
parseToJSON() {
let data = this.csvData;
for (var i = 0; i < data.length; i++) {
let row = [];
row.push(data[i].split(","));
const expense = new Object();
expense.date = row[0][0];
expense.category = row[0][2];
expense.description = row[0][3];
expense.amount = row[0][4];
this.jsonConvert = this.jsonConvert.push(expense);
}
this.renderTable = true;
},
},
};
</script>
jsonConvertis an object, not an array, so it has nopushmethod