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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:30:35+00:00 2026-05-27T17:30:35+00:00

may be you can help me. How can I create global object and function

  • 0

may be you can help me. How can I create global object and function that return object values by id?

Example:

var chat = {
    data : {
      friends: {}
    }
}

....
/*
JSON DATA RETURNED:
{"users": [{"friend_id":"62","name":"name","username":"admin","thumb":"images/avatar/thumb_7d41870512afee28d91.jpg","status":"HI4","isonline":""},{"friend_id":"66","name":"Another name","username":"regi","thumb":"images/avatar/thumb_d3fcc14e41c3a77aa712ae54.jpg","status":"Всем привет!","isonline":"avtbsl0a6dcelkq2bd578u1qt6"},{"friend_id":"2679","name":"My name","username":"Another","thumb":"images/avatar/thumb_41effb41eb1f969230.jpg","status":"","isonline":""}]}
*/

onSuccess: function(f){
   chat.data.friends    = {};
   for(var i=0; i< f.users.length;i++){
      chat.data.friends.push(f.users[i])
   }
}

How can I create a new function (It will return values by friend_id)?

get_data_by_id: function (what, friend_id) {

/*obj.what = getfrom_globalobject(chat.data.friends???)*/
}

Example of use:

var friend_name     = get_data_by_id(name, 62);
var friend_username = get_data_by_id(username, 62);
var friend_avatar   = get_data_by_id(thumb, 62);
  • 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-27T17:30:36+00:00Added an answer on May 27, 2026 at 5:30 pm

    Try:

    get_data_by_id: function (what, friend_id) {
       return chat.data.friends[friend_id][what];
    }
    

    … but use it like:

    var friend_name     = get_data_by_id('name', 62);
    

    …and set up the mapping with:

    for(var i=0; i< f.users.length;i++){
      chat.data.friends[f.users[i].friend_id] = f.users[i];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

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
I can't tell from the Python documentation whether the re.compile(x) function may throw an
How can I get the (physical) installed path of a DLL that is (may
I can't think of an example where the reference count of a file may
I have a little dilemma that maybe you can help me sort out. I've
I want to create a html page that can be used to upload videos
May be you can help me with my task. I have a JSON string:
May I know know I can trigger system to repaint nth row in JList?
This may be a basic question but how can I include a module with

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.