H
H
hsuper2018-02-27 20:13:37
JavaScript
hsuper, 2018-02-27 20:13:37

How to open a js file locally?

for example, there is an input with the file type and by clicking on the button you need to find out the number of characters in the file without uploading it to the server, how to implement it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alvvi, 2018-02-27
@hsuper

const file = // здесь файл с инпута; 
const reader = new FileReader()

reader.onloadend = function(e) {
    if (e.target.readyState == FileReader.DONE) { 
      console.log(e.target.result.length) 
    }
};

reader.readAsText(file)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question