Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8187497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:34:49+00:00 2026-06-07T02:34:49+00:00

Im trying to create a node.js chat application and when someone joins the chat

  • 0

Im trying to create a node.js chat application and when someone joins the chat room I want to push the last 100 messages to their browser. I have node.js adding each chat message as an object with the username and text of the message into an array. When node.js pushes the array of objects it looks like this.

[
    [
        {
            "username": "Warren2",
            "text": "test1"
        },
        {
            "username": "Warren2",
            "text": "test2"
        },
        {
            "username": "Warren2",
            "text": "test3"
        },
        {
            "username": "Warren2",
            "text": "hello"
        }
    ]
]

I’m having trouble parsing that with jquery and I think jquery is throwing errors because the objects are inside an extra set of brackets. The code I’m using to create the array of objects is as follows:

// chat history
var history = [];

// when the client emits 'sendchat', this listens and executes
socket.on('sendchat', function (data) {
    // we tell the client to execute 'updatechat' with 2 parameters
    io.sockets.emit('updatechat', socket.username, data);
    // we add the message to the chat history
    var obj = {username:socket.username,text:data};
    history.push(obj);
    history = history.slice(-100);
});

Am I doing something wrong or is there a way to remove the extra set of brackets or parse this with jquery? When I log the history data node.js is sending to the browser to the console it looks like this:

[Object { username="Warren2", text="test1"}, Object { username="Warren2", text="test2"}, Object { username="Warren2", text="test3"}, Object { username="Warren2", text="hello"}, Object { username="Warren", text="test"}, Object { username="Warren", text="test again"}, Object { username="Warren", text="test"}, Object { username="Warren", text="Hey"}]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:34:51+00:00Added an answer on June 7, 2026 at 2:34 am
    $.each(data, function(index,el) {
        // el = object in array
        // access attributes: el.Id, el.Name, etc
    });
    

    Found it in another stackoverflow post. Haven’t seen this being used before but after parsing the incoming data with

    var json = $.parseJSON(data);
    

    The above code worked perfectly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi I'm trying create chat using node.js I see example in http://chat.nodejs.org/ I have
I am pretty new to CoffeeScript. I am trying to create Node.js application using
I'm trying to create a basic Node application, every time a client connects I
Does someone knows several apps that currently use Node.js?, I'm trying to create a
I'm trying to create a facebook/gtalk custom chat window. Already created a Facebook application
I'm trying to create a websocket server with Node.js to run on a Windows
I'm trying to create a module/class in node.js to measure asynchronous execution time but
I am trying to create a tree like node diagram, like the example image
I'm trying to create a 2 dimensional array of Node objects as follows public
I'm trying to use Node.js to create a zip file from an existing folder,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.