I have indeed found many questions that sounded similar but none worked in my case. Fairly new to OOP so please bear with me.
console.log(result)
returns object below successfully:
[
{ name: 'horse', lid: 1 },
{ name: 'cat', lid: 2 },
{ name: 'dog', lid: 3 }
]
I'd like the output to be
[
{ name: 'horse' },
{ name: 'cat' },
{ name: 'dog' }
]
I know I can make the query fetch name only but what I am after is having full data set in result
then choosing what properties to be displayed and what properties to be skipped for all objects.
My attempts so far
console.log(result[0].name + result[1].name + result[2].name);
=>Success but what if I have 1000 objects ?
for (let i = 0; i <= result.length; i++) {console.log(result[i].name);}
=> Failed and returns Cannot read properties of undefined
result.forEach(arr => {
for (const key in arr) {
// console.log(arr[key].name);
console.log(arr[key]['name']);
}
});
Also failed and returns Cannot read properties of undefined