Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
WebSocket Javascript onMessage handling multiple objects

I'm using a websocket with React, I'm connecting to it and when I try to get data from the server with on message, I receive multiple object and I cannot handle them. my code:

 const chatSocket = new WebSocket(`wss://myurl/${key}/${user.id}`)
    chatSocket.onopen = (e) => {
      console.log("[open] Connection established");
      chatSocket.send({
        'type': 'online_users'
      })
    }

    chatSocket.onmessage = (e) => {
      const message = JSON.parse(e.data);
      console.log(message);
    }

what I receive: enter image description here I'm trying to access the data in the type : 'online_users'.

I tried to push everything in one array, did not work and by calling:

console.log(message.type);
console.log(message.data);
console.log(message[0]);

it does not work either.

Thanks.

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!