Estoy tratando de cargar un archivo de texto que contiene 1 y 0 como cadenas en algún orden y luego imprimo "azul" o "rojo" en función de si es un 1 o un 0. Aquí está mi código hasta ahora
var file = document.getElementById('inputfile'); file.addEventListener('change', () => { var txtArr = []; var fr = new FileReader(); fr.onload = function() { // By lines var lines = this.result.split('\n'); for (var line = 0; line < lines.length; line++) { txtArr = [...txtArr, ...(lines[line].split(" "))]; } } fr.onloadend = function() { console.log(txtArr); document.getElementById('output').textContent = txtArr.join(""); } fr.readAsText(file.files[0]); }) window.console = { log: function(str) { var node = document.createElement("div"); node.appendChild(document.createTextNode(str)); document.getElementById("myLog").appendChild(node); } } for (i = 0; i < txtArr.length; i++) { if (txtArr[i] = 1) { console.log('blue'); } else if (txtArr[i] = 0) { console.log('red'); } } <!DOCTYPE html> <html> <head> <title>Read Text File</title> </head> <body> <input type="file" name="inputfile" id="inputfile"> <br> <pre id="output"></pre> <p id="myLog"></p> </body> </html>el resultado es este
¿Cómo puedo usar la matriz que hice a partir del documento de texto en una matriz con la que realmente puedo trabajar e imprimirla en html?