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

  • Home
  • SEARCH
  • 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 7160289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:22:29+00:00 2026-05-28T13:22:29+00:00

I have an array of data that is returned as a JSON response. The

  • 0

I have an array of data that is returned as a JSON response. The data will be regularly updated, and will also be accessed very frequently.

The data contains a list of comments/replies for each song on display and is accessed when the user hovers over a particular element, and the specific comment/reply is then rendered to a template.

The list of songs is also dynamically filterable and the array will therefore be constantly updating.

Given the frequent access and updates of this data which of the following would be considered best practice:-

A. Store the whole array in a global variable and constantly manipulate it/access it.

or

B. Store the array in the DOM using jQuery’s $.data method and access it that way.

Which would be best and why… If option A please bear in mind that the variable will need to be held in memory throughout the users session. Also is there anything I need to watch out for in terms of potential memory leaks etc?

EDIT: Just to provide some more information: On average I would expect the data to be between 2-5kb at any given time.

  • 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-28T13:22:30+00:00Added an answer on May 28, 2026 at 1:22 pm

    I’m going to have to say option B here. While the performance benefits of manipulating a pure array sounds really attractive, from what it sounds like, your usage of the data sort of necessitates relating your data to the individual DOM elements they apply to.

    With $.data, you’re attaching data to the element that they pertain to. Imagine the workflow of your hover event:

    // with option A
    $('.song').mouseover(function (e) {
        // read the relevant index value of the data from this element
        // (probably through some attribute?)
    
        // get the data from the global array
    
        // show that data on hover
    });
    
    // with option B
    $('.song').mouseover(function (e) {
        // show the $(this).data() on hover
    });
    

    It’s certainly cleaner, and I can’t imagine how you’re making your DOM elements remember their associated data in the global array, save from plugging it on the DOM element themselves via an attribute, or having an object reference somewhere.

    Secondly, global objects are evil. To some significant, prone-to-argument-and-debate-flamebait extent.

    Thirdly, it sounds like your song elements are sorting and filtering on the DOM themselves. If you attach your data via $.data, those get sorted and filtered along with the DOM elements without any additional tracking. A song element has to be erased from the DOM? Just call .remove() on it — the associated gets deleted as well. Free functionality!

    Lastly, $.data is also optimized to prevent circular references and memory leaks as well (correct me if I’m mistaken on that one).

    Besides, 2-5kb of data doesn’t sound like a whole lot.

    Just my two cents.

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

Sidebar

Related Questions

I have JSON data returned in my action controller: $results = $repo->getMatchingCityName($searchTerm); Response that
I'm looking for a kind of array data-type that can easily have items added,
I have a php array that has a bunch of data that I need
I have a class 'Data' that uses a getter to access some array. If
I have a model that I'm trying to retrieve an array of data from,
I have a two dimensional array that I need to load data into. I
I have two arrays of data that I'm trying to amalgamate. One contains actual
I have developed a script that receives json data from a php script using
I have 3 arrays of data, that are filled by reading off of an
I have an array: data.Dealer.car[0] data.Dealer.car[1] data.Dealer.car[2] If I do this: alert(data.Dealer.car.length); delete data.Dealer.car[1];

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.