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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:22:18+00:00 2026-06-13T10:22:18+00:00

This is probably very easy, but I just can’t figure out how to solve

  • 0

This is probably very easy, but I just can’t figure out how to solve it right now. Each time a submit button is clicked, the function below checks input field 1 (name), and if not empty adds the value to an associative array, and continue with the description.

What I want is to add a new level 1 element to the array every click, that should hold these value, so that it after three clicks looks like this:

Click 1:
    listObject[0]['listObjectName'] = 'Name 1';
    listObject[0]['listObjectDesc'] = 'Desc 1';

Click 2:
    listObject[1]['listObjectName'] = 'Name 2';
    listObject[1]['listObjectDesc'] = 'Desc 2';

Click 3:
    listObject[2]['listObjectName'] = 'Name 3';
    listObject[2]['listObjectDesc'] = 'Desc 3';

The function:

$('#addListObjectSubmit').click(function (e) {

            var listObjectName = $('#m_newListObject').val();

            if((listObjectName == null) || (listObjectName == '')) {
                return false;
            }
            else {
                listObjects['listObjectName'] = listObjectName;

                var listObjectDesc = $('#m_newListObjectDesc').val();

                if ((listObjectDesc == null) || (listObjectDesc == '')) {
                    listObjects['listObjectDesc'] = null;
                }
                else {
                    listObjects['listObjectDesc'] = listObjectDesc;
                }
            }

            e.preventdefault();
        });

So, what is the best way of dealing with this?

  • 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-13T10:22:19+00:00Added an answer on June 13, 2026 at 10:22 am

    It will help you a bit if you forget about associative arrays. They only theoretically exist in Javascript. In fact, everything is an object, even arrays. But thinking in data storage terms, you can use a simple array that can only be indexed numerically, or you can use an object as a data map.

    The following example creates an array (note the more compact [] instead of new Array()) and pushes a map (created with {}) into it:

    var listObjects = [];
    ...
    var newElem = {
        'listObjectName' : 'Name 1',
        'listObjectDesc' : 'Desc 1'
    };
    listObjects.push(newElem);
    

    Afterwards, you can access this element with listObjects[0], if it was the first element in the array.

    If you want to access its properties, you can use one of these:

    listObjects[0].listObjectName
    listObjects[0]['listObjectName']
    

    So you can see that when dealing with objects, you can use the . notation as well as the bracket notation – they are equivalent, but the latter form makes it look like it is an “associative array” (even more for people coming from PHP).

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

Sidebar

Related Questions

this is probably very easy to do, but I can't seem to figure it
This is probably very easy to do but for some reason I can't seem
This problem is probably very easy to solve but somehow I cannot find a
OK, this is probably very basic, but I can't find the problem. I'm trying
This is probably a very simple question so please forgive my ignorance, but can
Probably this is a very easy question, but I did not find yet how
I am just starting to learn C, this is probably a very easy question
I'm afraid this is probably a very embarrassingly easy question - but my mind
I have problem with margin. Probably its very easy to solve, but i dont
This is probably a really easy question, it's just very hard to google a

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.