0

I have fetched an API request and now access the values in the array I'm having issues. I see that all the objects are successful in the PromiseResult. But if I try object[0].propertyName I get it cannot be read.

Here is my full method and some stuff i tried.

 methods: {
        fetchByteArray() {
            this.post = true;
            this.loading = false;
            //Docs\003
            console.log("inside FetchByteArray");
            fetch('https://localhost:5001/api/Doc/GetFolder/003')
                .then(response => {
                    console.log(response.json());
                    //console.log(JSON.stringify(response));
                    //console.log(response.body);

                    let result = Promise.resolve(response);
                    result.then(val => console.log(val));
                })

                .then(bytes => {
                    //console.log(bytes);

                    //this.byteArrays = bytes;
                    console.log(bytes.fileName);
                })
                .catch(error => console.log(error.message));

[[PromiseResult]]
: 
Array(6)
0
: 
{fileID: 0, fileName: 'image00.png', fileExtension: '.png', filePath: 'C:\\Users\\user1\\Documents\\zTests\\Docs\\003', byteArray: 'System.IO.MemoryStream', …}
1
: 
{fileID: 1, fileName: 'image01.png', fileExtension: '.png', filePath: 'C:\\Users\\user2\\Documents\\zTests\\Docs\\003', byteArray: 'System.IO.MemoryStream', …}
Bigbear
  • 489
  • 2
  • 5
  • 21
  • It's `response.json().then(console.log);` not `console.log(response.json());`. You want to do `if (response.ok) return response.json(); else throw new Error(response.statusText);` so that you receive the promise result in the `.then(bytes => …)` handler in your promise chain. – Bergi Dec 13 '22 at 01:05
  • how to I get a value from an object in the array.. – Bigbear Dec 13 '22 at 18:13
  • Use `bytes[0].fileName` (or better some way to loop over the `bytes` array) in the second `then` handler after you followed my first advice. You can [edit] your question with your attempts if you need further help. – Bergi Dec 13 '22 at 20:48

0 Answers0