Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    What kind of array is this?

    What do you call this kind of javascript array?

    Code:
    var markers = [
          { lat: -33.85, lng: 151.05, name: "marker 1" },
          { lat: -33.90, lng: 151.10, name: "marker 2" },
          { lat: -33.95, lng: 151.15, name: "marker 3" },
          { lat: -33.85, lng: 151.15, name: "marker 4" }
        ];
    markers[0].name= "wow I was able to do this";
    I don't see any javascript documentation on this.

  • #2
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I guess you call them :

    One can use the object declaration literal to create objects that behave much like associative arrays in other languages:
    Code:
    dog = {"color":"brown", "size":"large"};
    dog["color"]; // results in "brown"
    dog.color;    // also results in "brown"
    One can use the object and array declaration literals to quickly create arrays that are associative, multidimensional, or both. (Technically, JavaScript does not support multidimensional arrays, but one can mimic them with arrays-of-arrays.)

    Code:
    cats = [{"color":"brown", "size":"large"},
            {"color":"black", "size":"small"}];
    cats[0]["size"];      // results in "large"
     
    dogs = {"rover":{"color":"brown", "size":"large"},
            "spot":{"color":"black", "size":"small"}};
    dogs["spot"]["size"]; // results in "small"
    dogs.rover.color;     // results in "brown"

  • #3
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,091
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Arrow

    Quote Originally Posted by gamshaft View Post
    What do you call this kind of javascript array?

    Code:
    var markers = [
          { lat: -33.85, lng: 151.05, name: "marker 1" },
          { lat: -33.90, lng: 151.10, name: "marker 2" },
          { lat: -33.95, lng: 151.15, name: "marker 3" },
          { lat: -33.85, lng: 151.15, name: "marker 4" }
        ];
    markers[0].name= "wow I was able to do this";
    I don't see any javascript documentation on this.
    Expanding on your post.
    Code:
    <script type="text/javascript">
    var markers = [
          { lat: -33.85, lng: 151.05, name: "marker 1" },
          { lat: -33.90, lng: 151.10, name: "marker 2" },
          { lat: -33.95, lng: 151.15, name: "marker 3" },
          { lat: -33.85, lng: 151.15, name: "marker 4" }
        ];
    var str = '';
    for (var i=0; i<markers.length; i++) {
      str += markers[i].name+'\t'+markers[i].lat+'\t'+markers[i].lng+'\n';
    }
    markers[0].name= "wow I was able to do this";
    str += '\n\n';
    for (var i=0; i<markers.length; i++) {
      str += markers[i].name+'\t'+markers[i].lat+'\t'+markers[i].lng+'\n';
    }
    alert(str);
    </script>


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •