I am facing an issue where I need to locate a value within an array of arrays, but the .find method is returning undefined.
import { Component, OnInit } from '@angular/core';
import * as XLSX from 'xlsx';
import { ExcelSheetsService } from '../services/excel-sheets.service';
@Component({
selector: 'app-hojaexcel',
templateUrl: './hojaexcel.component.html',
styleUrls: ['./hojaexcel.component.css']
})
export class HojaexcelComponent implements OnInit {
constructor( private excelsheetService: ExcelSheetsService ) { }
ngOnInit(): void {
}
codigo: any = '';
datos: [][] = [];
onFileChange( evt: any ){
const target: DataTransfer = <DataTransfer> (evt.target);
if(target.files.length !== 1) throw new Error ('No se pueden subir varios archivos a la vez');
const reader: FileReader = new FileReader();
reader.onload = ( e: any ) => {
const bstr: string = e.target.result;
const wb: XLSX.WorkBook = XLSX.read( bstr, { type: 'binary' } );
const wsname: string = wb.SheetNames[0];
const ws: XLSX.WorkSheet = wb.Sheets[wsname];
this.datos = (XLSX.utils.sheet_to_json(ws, { header: 1 }));
console.log(this.datos);
return this.datos;
};
reader.readAsBinaryString(target.files[0]);
}
look(): any{
const found = this.datos.find(element => element == this.codigo );
console.log(found);
console.log(this.datos);
}
pasardata(){
this.excelsheetService.impData( this.datos )
.subscribe( resp => {
console.log(resp);
});
}
}
The array containing arrays is referred to as datos. Below is the HTML:
<p>Upload Excel File</p>
<br>
<input type="file" (change)="onFileChange($event)" multiple="false" />
<br>
<button (click)="pasardata()">
Upload to Firebase Database
</button>
<br>
<div class="col">
<form (ngSubmit)="look()">
<input type="text" placeholder="Code" name="codigo" [(ngModel)]="codigo"/>
<button>Send</button>
</form>
</div>
I have attempted to access the datos array of arrays and it returns an empty array. My goal is to utilize the array of arrays to display a table and then retrieve a specific value from the table using the .find() method.