Home > Net >  Pull specific information from the filter;
Pull specific information from the filter;

Time:10-18

I'm currently tweaking a system, so during the process, I wanted to implement real-time information search, so the following code was:

<%= results7.filter(i => i.nick === req.autor) %>

A note of the code above, which in console.log looks like this: console . Until then, everything is ok, he is actually pulling the information as requested, an observation is that the req.autor came from <%infoReq.forEach(req => {%> And all of this is collected by index.js through res.render('./requerimentos/corpomilitar/corpomilitar.ejs', { infoReq: results23, wait: wait.length, info: req.session.user, nickname: req.session.user.nick, message: req.flash('erro'), current: pagina, paginas: totalReqPorPagina, results3, patente: req.session.user.patente, results7,

Already tried <%= results7.filter(i => i.nick === req.autor)['nPostagens'] %> or <%= results7.filter(i => i.nick === req.autor).nPostagens %> and gives undefined, while o <%= results7.filter(i => i.nick === req.autor)i.nPostagens %> gives missing ) after argument list. PS: The system is fully configured in EJS, NODEJS and MYSQL. The con queries are: con.query(SELECT *, RANK() OVER (ORDER BY id DESC) FROM req_cm LIMIT ${pular},${dadosPorPagina}, (err, results23) => { and con.query(SELECT * FROM users, (err7, results7) => {

So I would like to request help to pull the specific "nPostagens" information that respects the filter.

CodePudding user response:

It is hard to get what you are asking as the code in the question is unformatted and difficult to read. However, the .filter method returns a new array. so trying to access .nPostagens would not work. If you know there will only be one item in the array, and it is an object, you can try:

results7.filter(i => i.nick === req.autor)[0].nPostagens
  • Related