I have this function where I have 2 parameters, I use the "field" parameter to access an object but it takes it as an attribute of the object and does not refer to my parameter.
async id(modelo, campo){
const data = await modelo.all()
console.log(data)
var idmayor = 0
for (let i = 0; i < data.rows.length; i++) {
const id = data.rows[i].campo;
if(id > idmayor){
idmayor = id
}
console.log(idmayor)
}
idmayor + 1
return idmayor
}
Here it can be shown better that it does not refer to the parameter "field"
Thank you
It is that you ask for the field property. Object properties can also be read like the elements of arrays, strings, and other lists.
In this case change the .field to [field]
You are now accessing the property of the object whose name is noted in the field variable.