Unable to execute any actions on object in JavaScript

I currently have two functions in my code: getRawData() and getBTRawData().

  1. The purpose of getBTRawData() function is to retrieve data from Bluetooth connected to a mobile device.
  2. On the other hand, getRawData() function takes the return value from getBTRawData() but encounters some issues when trying to iterate over it. Although I can successfully print the value within a promise, I am unable to perform any operations on it.

getRawData() {

        const result = this.getBTRawData().then((item) => {
            console.log("Item retrieved: ", item);
            let flatten = [];
            for(let i in item) {
                console.log("something happening here");
                flatten.push(...item[i]);
            }

            console.log(flatten);

        }).catch(err => {
            console.log(err);
        });

    }

    async getBTRawData() {
        let result = [];
        const res = await this.bluetoothSerial.subscribeRawData().subscribe((data) => {
            //console.log("raw data");
            // console.log(data);
            var buffer = new Uint8Array(data);
            //this.raw_data_c.push(buffer);
            result.push(buffer);
            //console.log(this.raw_data_c);).map(
            // console.log(result);
        });

        return result;
    }

Any assistance or insights on how to resolve this issue would be greatly valued. Thank you.

Answer №1

The function getBTRawData appears to be yielding an array instead of a Promise. In this case, you may consider manipulating the data directly from getBTRawData within the getRawData function (assuming all other components are functioning correctly).

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

There was a problem establishing a WebSocket connection to 'ws://127.0.0.1:2000/'. The attempt failed with the following error: net::ERR_CONNECTION_REFUSED

I have integrated websocket functionality using a repository found at https://github.com/kishor10d/CodeIgniter-Ratchet-Websocket After successfully testing the websocket on my local environment, I encountered issues when uploading the files to the live se ...

Learn How to Implement Styling in Material UI using Styled Components

Utilizing styled-components with MaterialUI integration. Encountering the following error in LoginTextField component and seeking a resolution. Error Message: [ts] Type '{ width: number; }' is missing the following properties from type &apos ...

Querying multiple attributes in express-restify-mongoose

Issue: I am attempting to send a query from my Angular2 frontend to my Node.js server using express-restify-mongoose. The goal is to search for data based on multiple attributes, instead of just one. Current Working Solution: let regex = '{"title": ...

Firebase initialization unsuccessful due to incorrect directory placement

I've been encountering an issue while deploying my Angular 2 project to Firebase. The initial deployment was successful, but subsequent attempts only show the Firebase Hosting welcome page instead of my project in the URL. I've realized that even ...

What could be the reason for receiving an undefined value when trying to determine the size of the Set

Within one of my functions, I am encountering the following code: this.personService.getPersonInfo(this.personId).subscribe((res => { let response = res.body; let num = response.personList.size; ... })) Here is what the expe ...

How can I display a pre-existing div with a dropdown button?

I have individual div elements for each type of clothing item (shirt, pant, suit) that I want to display when the corresponding service is selected. This means that when I click on one of them, only that specific div will be shown. I am looking for a solut ...

Modifying Data in Another Component in VueJS

I have a classic Vue Component structured like the following: Vue.component('bar', { template: `<div class="bar"></div>`, data () { return { blocks: [ ] ...

Is there a chance of a race condition occurring during file uploads when processed individually through AJAX with PHP?

I have created a form for uploading multiple files. <form id="myuploadform" enctype="multipart/form-data"> <input id="uploadedFiles" name="uploadedFiles" type="file" class="form-control&qu ...

Can you indicate a specific version of an npm module without making changes to the package.json file?

I am looking to update the version of a npm module without making changes to the package.json file. I want to avoid forking the repository if possible. If the package.json appears similar to this: ... "dependencies": { "iwan ...

Attempting to eliminate the readonly attribute from HTML using Python

Seeking assistance with removing the readonly tag from an input field using Python and Selenium. Can anyone lend a hand? Datepicker Image: HTML: <input id="startDate" name="START_DATE" type="text" class="date hasDate ...

Move and place, editing tools

Is it possible to create a drag-and-drop editor similar to the one found in the form editor on wufoo.com? ...

What is the most effective way to leverage rxjs for executing multiple asynchronous fetch operations in one go using a forEach strategy?

As a newcomer to React, I have been assigned the task of modifying an existing application that already makes multiple API calls. The current pattern in use is illustrated below. For example, if an action mapperActions.selectPolygon of type CaseReducerActi ...

What is the most efficient way to use jQuery to retrieve the count of tags associated with a variable

I am trying to filter my data retrieved from ajax using a function. Here is the initial code: var csvf = data.filter(function (el) { return ['TRUCK_CPX'].indexOf(el.TAG) >= 0 && ['CA5533'].indexOf(el.Chave) >= 0 }); Now ...

What are some strategies for reducing the data transmitted by clients over a websocket connection?

Currently, I am utilizing the ws module and I have a need to restrict the data sent by clients over websocket to 1Mb. By setting this limit, it will deter any potential malicious users from inundating the server with large amounts of data (GB scale), poten ...

The library 'material-ui' does not have a 'withStyles' export available

Here is the content of my package.json file. Everything was working fine until recently when I started encountering this error. "@material-ui/icons": "1.0.0-beta.42", "chartist": "0.10.1", "classnames": "2.2.5", "material-ui": "1.0.0-beta.41", "npm-ru ...

Diving deep into the reasons behind a test's failure

Currently, I am using Postman to test the API that I am developing with express. In this process, I am creating a series of tests. Below is a brief example: tests["Status code is 200"] = responseCode.code === 200; // Verifying the expected board var expe ...

Update the content in the Bootstrap modal

I'm currently implementing modal Bootstrap in my ASP.NET website. I have encountered an issue where the text in the modal does not change according to the errors returned in the code behind, even after modifying the text value of the control before ma ...

Ensure the presence of a value in an array using Angular

I need to check if any of the "cuesData" have values or lengths greater than 0. However, in my current code, I can only evaluate the first array and not the rest. https://i.sstatic.net/bMpvg.jpg TS checkValues(values) { const result = Object.values ...

Creating interactive PDF files using ReactJS

Is there a way to create a PDF using React that supports styling and allows the content to be hidden on the page? I need to have a link in my app that, when clicked, generates a PDF and opens it in a new tab. I've tried out various packages but none s ...

What is the best way to create a dynamic information page using both V-for and V-if in Vue.js?

Hey everyone, I recently attempted to set up this layout: https://i.sstatic.net/WbcBX.png This company offers a variety of services grouped into different categories, each containing sub-options and specific details. This is how my JSON data is structur ...