An array within another array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • manojrana
    New Member
    • Jan 2009
    • 5

    An array within another array

    Can we store an array within another array in javascript

    Code:
    var locat = new Array();
    var element = new Array();
    locat[] = element;
    or Can we use like this
    Code:
    locat['name'][0] = "manoj";
    locat['address'][1] =  "Noida";
    Please let me know the possible way
    Last edited by gits; Jan 7 '09, 06:32 PM. Reason: added code tags
  • xNephilimx
    Recognized Expert New Member
    • Jun 2007
    • 213

    #2
    Yes you can, but not the way you want, associative arrays doesn't exist in javascript, what you need is an array with objects inside.
    I also recommend you the json syntax, is easier and cleaner.

    Something like this:
    Code:
    var locat = [
        {'name':'manoj', 'address':'Noida'},
        {'name':'some other name', 'address':'some other address'},
        {'name':'etc...', 'address':'etc...'}
    ];
    
    alert( locat[0].name ); //this will alert "manoj"
    alert( locat[1].address ); //this will alert "some other address"

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      you don't need the quotation marks around the property names.
      Code:
      var locat = [
          {name:'manoj', address:'Noida'},
      // ...
      ];
      if you have many objects to insert, maybe consider using a constructor function.

      regards

      Comment

      • xNephilimx
        Recognized Expert New Member
        • Jun 2007
        • 213

        #4
        Originally posted by Dormilich
        you don't need the quotation marks around the property names.

        You don't needed but it's reccomended, to reduce the load on the js engine, and semantically, anything without quotes in js tries to be parsed as a variable, that's why if you quote it, you avoid making the engine
        do an extra unnecessary check.
        Anyways, it's not like it will make the script crash if you don't use them ;)
        I just use them whenever I feel so

        Comment

        • rnd me
          Recognized Expert Contributor
          • Jun 2007
          • 427

          #5
          Originally posted by Dormilich
          you don't need the quotation marks around the property names.
          he was talking about JSON though, in which case you would.

          double quotes too, not single quotes.

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            I don't know if Javascript will try to read it as object literal or JSON in the first place, thus the remark.

            Comment

            • manojrana
              New Member
              • Jan 2009
              • 5

              #7
              integrate an IVR application

              I have a web application , now I want to have IVR implementation , I will be using IVR which is a third party with my application.
              Please guide me how should I start to integrate IVR with my application as my application will interac with my database.
              Will I be rading and writing the response to the third party(IVR) ?

              Comment

              • gits
                Recognized Expert Moderator Expert
                • May 2007
                • 5390

                #8
                are you talking about something like this?

                Comment

                • manojrana
                  New Member
                  • Jan 2009
                  • 5

                  #9
                  index caching

                  when we create index on tables , do the indexes gets cached or not by default.
                  Or we have to manually LOAD THE INDEXES INTO THE CACHE

                  Comment

                  • gits
                    Recognized Expert Moderator Expert
                    • May 2007
                    • 5390

                    #10
                    please specify your question more clearly ... i guess! that you mean database-tables and in case you do you should post in the appropriate forum since this ... the current forum where you have posted it ... is the JavaScript-forum and doesn't deal with such kind of questions ...

                    kind regards,
                    MOD

                    Comment

                    Working...