link548 link549 link550 link551 link552 link553 link554 link555 link556 link557 link558 link559 link560 link561 link562 link563 link564 link565 link566 link567 link568 link569 link570 link571 link572 link573 link574 link575 link576 link577 link578 link579 link580 link581 link582 link583 link584 link585 link586 link587 link588 link589 link590 link591 link592 link593 link594 link595 link596 link597 link598 link599 link600 link601 link602 link603 link604 link605 link606 link607 link608 link609 link610 link611 link612 link613 link614 link615 link616 link617 link618 link619 link620 link621 link622 link623 link624 link625 link626 link627 link628 link629 link630 link631 link632 link633 link634 link635 link636 link637 link638 link639 link640 link641 link642 link643 link644 link645 link646 link647 link648 link649 link650 link651 link652 link653 link654 link655 link656 link657 link658 link659 link660 link661 link662 link663 link664 link665 link666 link667 link668 link669 link670 link671 link672 link673 link674 link675 link676 link677 link678 link679 link680 link681 link682 link683 link684

[Vue.js] 'i is not defined' at FileReader.reader.onload VueJs

I cant execute a for loop nor a forEach in an array because its says that i is not defined

there is already tried to use a while, a for, a for each. Use i like a vue.js data variable.
I set that let self = this, because the scope changes within that reader.onload. and I know that the problem has to be with something like that.

<p>My File Selector: <file-select v-model=”file”></file-select></p>
<p v-if=”file”>{}</p>
<v-btn v-if=”file” @click=”importFile”>Import</v-btn>
<div id=”fileContents”>


import icsToJson from ‘ics-to-json’
import FileSelect from ‘./FileSelect.vue’

export default {
name: “ViewImport”,
components: {
return {
file: null,
fileInJson: null,
categories: [],
importExists: false,
//this works
//code, this works
for (var i = 0; i < this.categories.length; i++){
if (this.categories[i] === ‘Import’){
this.importExists = true;
// break;
if (this.file) {
let reader = new FileReader();
reader.readAsText(this.file, “UTF-8”);
let self = this;
reader.onload = function (evt) { //If everything works
//Changes the file to format JSON
self.fileInJson = icsToJson(;

self.doesImportExists();//the loop

if (self.importExists){
console.log(‘Category exists’);
//other method
console.log(‘not working’); //Because its in my BD
// self.importCreatingCategoryImport();

reader.onerror = function (evt) { //if it doesn’t
document.getElementById(“fileContents”).innerHTML = “error reading file”;

//style commented

Solution :

That’s because in the data section you have not assigned a value to key i. You should do i : 0 in the data, and in for loop let j = this.i; j < this.categories.length; j++)