Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    wrong length in Array

    What wrong in this code:

    Code:
        var newArray = new Array();
        newArray.add("aaa","bbb");
        alert (newArray.getLength());
        newArray.add("ccc","ddd");
        alert (newArray.length);
    first alert return value 0 and second alert return value 0.

    I think that there should be 1 and 2, is not it?

    #2
    add() has one declared parameter, but you're passing two. The second parameter is being taken as a position for insertion because of a shared codepath with addAt().

    Comment


      #3
      ok, but how correctly into hash "aaa" put value "bbb"?

      Comment


        #4
        Hi Breeze,
        I think you may be confusing Arrays and Objects here
        If you want an object with a property aaa who's value is bbb, you can take several approaches

        Code:
        var myObj = new Object();
        myObj.aaa = "bbb";
        
        // OR
        var myObj = {};
        myObj.add = "bbb"
        
        // OR
        var myObj = {aaa:"bbb"}
        
        // Or even
        var myObj = {}
        isc.addProperties(myObj, {aaa:"bbb", ccc:"ddd"}
        You could examine how many properties an object has via isc.getKeys(myObj).getLength()

        By comparison a JS array is essentially simply an ordered list of values.

        Comment


          #5
          Тhank you very much

          Comment

          Working...
          X