-3
First of all, I’ve already researched about, but I couldn’t, at least not in a simple way and it was supposed to work. Well I have a variable that contains this following array when I give a console
[
 {
  Id: 1,
  User: 'User',
  Password: 'Dn',
  Nome: 'Fhdnd',
  Sobrenome: 'Js'
 } 
]
This is the array of users, but this I want to get only the password? It was not supposed to work with rows[2] ?
What I hoped was that you would return:
[
  {
    Password: 'Dn'
  }
]
Error: Undefined
The only way I can achieve this goal is with foreach?
Obs: Rows is the name of the variable that contains this array
My full function where I’m trying to solve the problem
async function verify(req,res,username,password){
 db.serialize(async function (){                               
  const query = 'SELECT * from Users WHERE User = (?) AND Password = (?)'                                                     
 db.all(query,[username, password],async function(err,rows){    
  try{
   if(rows.length == 1){                                          
    console.time("time1")                                         
    await console.log(rows);                                      
    console.log("Correct user");                                                                                                                
    res.render(__dirname + "/View/Home/index.handlebars");
    rows[2]                                          
    console.timeEnd("time1")                                       
     }
    else{
     console.log("Incorrect user!")}}
    catch{
    console.error("\x1b[31m","Problema com a função de autenticação, erro: \n", err);
    }
  })
})}
This is where I want to access the index exactly, I’m calling the function, I just didn’t post everything because this is where the function should show the index I want to access etc ... I’m just not posting the rest because I’m not having a problem with the rest of my code.
It may be that I come from more than one object in the array, ie I will add more users over time.
Comment on what to improve on the question because it seems clear to me.
– user212376
William, what you have is an array with an object inside.
– Gato de Schrödinger
And how to access this password? To be able to display only the password and not the entire array
– user212376
I’ve already edited the August question
– user212376
Assign those values to a variable. And, based on your code, for you to access the password, it would look like this: array[0]. Password
– Gato de Schrödinger
Above, "array" would be the name of the variable. Take a closer look at this code: https://codepen.io/Kravin/pen/XWjBwRQ
– Gato de Schrödinger
But these values need to be dynamic because I might delete some user or create one, and I will use these values in another file so it would be kind of complicated if I have 100 users downloads? Then I would have to add 100 times these values into a variable.
– user212376
You can convert my "array" to json to achieve my goal?
– user212376
There really would have to be a foreach. Add this information to the question, which may be several objects within the array, so we can elaborate the correct answer.
– Gato de Schrödinger
Okay, sorry kkk.
– user212376
Of good, Guillermo.
– Gato de Schrödinger
Boy, the guys here like to downvote everything, huh?
– davidbuzatto