Hi there,
I have a variable called response, made by a Mongoose query and if I console.log it, it comes out as:
[
{ projectname: ‘testproject’ },
{ projectname: ‘testprojectnotreal’ }
]
I need just [‘testproject’, ‘testprojectnotreal’], but if I use console.log(response[‘projectname’]) it comes back as undefined. How do I get it as I want it?
Eddie
Changing “response” to this will work:
{projectname: [‘testproject’, ‘testprojectnotreal’]}
You don’t need an Array of Objects, but use an Array for the properties of the Object.
Thanks, yep.
Found I need to do this instead:
response[0].projectname;
Ok, but it doesn’t return an Array and return a String, is it a problem? If not, there’s no longer need of discussion about this.
Got it working with this code:
const iterator = response.values();
for (const value of iterator) {
urls.push(value['projectname']);
console.log(urls);
}
Surprisingly it works!
Thanks for the help
Eddie
bruh you used that way. Anyway don’t forget to mark this as solved