У меня есть функция, которая извлекает и отображает значения csv файла.
функция
var IDArr = [];
var fileInput = document.getElementById("csv");
readFile = function() {
console.log("file uploaded")
var reader = new FileReader();
reader.onload = function() {
// document.getElementById('out').innerHTML = reader.result;
// I assigned the IDs retrieved from the CSV file to an array named keys
IDArr.push(reader.result);
// var keys = [reader.result];
var promises = IDArr.map(function(key) {
return firebase.database().ref("/Agents/").child(key).once("value");
});
// read the data from the database for each ID
Promise.all(promises).then(function(snapshots) {
snapshots.forEach(function(snapshot) {
console.log(snapshot.key + ": " + snapshot.val());
});
});
};
// start reading the file. When it is done, calls the onload event defined above.
reader.readAsBinaryString(fileInput.files[0]);
};
if (fileInput) {
fileInput.addEventListener('change', readFile);
}
вышеуказанная функция обрабатывает изображение ниже
мне нужно поставить кавычку вокруг каждого значения идентификатора и разделить каждую запятую. Так, например, я хочу создать новый массив, который выглядит так: "75799757", "9744710", "79989647", "99029704", как я могу это реализовать?
let str = "ID 75799757 9744710 79989647 9902970";
let arr = str.split(" ").splice(1);
let result = arr.map((val) => '"'+val+'"').reduce((a,b) => a+','+b);
после этого результат выглядит так: "75799757","9744710","79989647","99029704"
var str = ...;
var parts = str.split(" ");
str = "'" + parts[0] + "'";
for (var i = 1; i < parts.length; i++) {
str += ",'" + parts[i] + "'";
}