I am trying to add some html tags and list as a string to var in javascript. So that I can replace later that code in html.
app.use('/index', function(req, res) {
var query = req.query;
var searchQuery = query.search;
for(i = 0; i < 11; i++){
if (data[i].indexOf(searchQuery) != -1){
console.log(data[i]);
//document.getElementById("".innerHTML = )
newdata.concat("<li>",data[i],"<li><br>");
console.log(newdata);
}
};
console.log(newdata);
var fileContent = fs.readFileSync(path.join(__dirname, '/public/index.html'), "utf8");
res.send(fileContent.replace("{{data}}", newdata));
});
I am trying to add info to newdata but concat doens't seem to work. Can you please help me and tell me why? I print data before adding to newdata with concat, but after additon newdata is still empty. WHY?
Just in case whole code is here
var express = require('express');
var path = require('path');
var app = express();
var port = process.env.PORT || 3000;
var fs = require ('fs')
var data = ['yellow','mellow','hello','yellow jaws','jaws','jaws 2','jaws 3','mellow jaws','angry jaws','angry jews','angry yellow juice'];
var newdata = '';
app.use(express.static(path.join(__dirname, '/public')));
app.use('/index', function(req, res) {
var query = req.query;
var searchQuery = query.search;
for(i = 0; i < 11; i++){
if (data[i].indexOf(searchQuery) != -1){
console.log("VATO");
console.log(data[i]);
//document.getElementById("".innerHTML = )
newdata.concat("<li>",data[i],"<li><br>");
console.log(newdata);
}
};
console.log(newdata);
var fileContent = fs.readFileSync(path.join(__dirname, '/public/index.html'), "utf8");
res.send(fileContent.replace("{{data}}", newdata));
});
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname, '/public/index.html'));
});
app.listen(port, function() {
console.log('App is listening on port ' + port);
});