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 6996001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:06:05+00:00 2026-05-27T20:06:05+00:00

May be you can help me with my task. I have a JSON string:

  • 0

May be you can help me with my task. I have a JSON string:

{
    "chats":[
        {"id":"1","time":"13:02", "from_id":"2692","text":"1","to_id":"62"},
        {"id":"2","time":"13:48", "from_id":"62","text":"Hello!","to_id":"2692"},
        {"id":"12","time":"15:47", "from_id":"2692","text":"3","to_id":"62"},
        {"id":"13","time":"15:48", "from_id":"62","text":"4","to_id":"2692"},
        {"id":"30","time":"08:57", "from_id":"2692","text":"To me","to_id":"62"},
        {"id":"31","time":"09:28", "from_id":"66","text":"From user1","to_id":"2692"},
        {"id":"32","time":"09:29", "from_id":"66","text":"From user1","to_id":"2692"},
        {"id":"32","time":"09:29", "from_id":"2692","text":"From user1","to_id":"66"}
    ],
    "lastid": "32"
}

var my_id = 2692 /*My chats*/

/*Success JSON request below*/

onSuccess: function(m){
    var messages = [];
    var chanels = [];
    var chanels_u = [];
    for(var i=0; i<m.chats.length;i++){                     
        if (my_id != '' && m.chats[i].from_id != parseInt(my_id)){
            chanels.push(m.chats[i].from_id);
        }
    }
    chanels_u = chanels.unique(); /*We get id's: 62,66*/
}

My Question:

How can I create a new arrays dynamically (2 for this example for: 62 and 66) and push messages?

To 1 (62):

{"id":"1","time":"13:02", "from_id":"2692","text":"1","to_id":"62"},
{"id":"2","time":"13:48", "from_id":"62","text":"Hello!","to_id":"2692"},
{"id":"12","time":"15:47", "from_id":"2692","text":"3","to_id":"62"},
{"id":"13","time":"15:48", "from_id":"62","text":"4","to_id":"2692"},
{"id":"30","time":"08:57", "from_id":"2692","text":"To me","to_id":"62"}

To 2 (66):

{"id":"31","time":"09:28", "from_id":"66","text":"From user1","to_id":"2692"},
{"id":"32","time":"09:29", "from_id":"66","text":"From user1","to_id":"2692"},
{"id":"32","time":"09:29", "from_id":"2692","text":"From user1","to_id":"66"}

Thanks!

  • 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-05-27T20:06:05+00:00Added an answer on May 27, 2026 at 8:06 pm

    You are already identifying your chat ID and pushing it into the chanels array in your code:

    if (my_id != '' && m.chats[i].from_id != parseInt(my_id)){
                chanels.push(m.chats[i].from_id);
    }
    

    You are also identifying unique IDs in your code:

    chanels_u = chanels.unique();
    

    All you need to do is locate your chats from the JSON object by comparing them to the IDs in chanels_u and if there’s a match, push the text field to the messages array. This is should be close to what you require:

    for(var i=0; i<m.chats.length;i++){                     
        for(var j=0; j<chanels_u.length;j++){
            if (my_id !== '' && m.chats[i].from_id === chanels_u[j]){
                messages.push(m.chats[i].text);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't tell from the Python documentation whether the re.compile(x) function may throw an
I hope someone may be able to help! We have a pretty large VB.Net
Can anyone please help me. I have developed macro that keeps track of huge
May I know know I can trigger system to repaint nth row in JList?
May be a stupid questions but can I protect a row of data in
how can I provide feedback for a shell command that may run for quite
This may be a basic question but how can I include a module with
How can I get the (physical) installed path of a DLL that is (may
I'm may be missing something but I can't find the Delphi 2007 WSDL Importer
May be I am getting old, but I can't find it...

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.