push in multi-dimensional, associated mass



  • How does JavaScript realize the following?

    The html components are tested in the cycle, and the first steps of the cycle should look:

    (1) First element values check, first value equal num_1an element of the association is being created:

    {
       num_1:{val_1: val_2}
    }
    

    (2) Test of the second element if the first value is equal num_1add a new element:

    {
       num_1:{val_1: val_2,
              val_3: val_4}
    }
    

    And so on. In other words, we have to put a new association at the end of the association. It's the method of handling the mass. Simple push only works with the usual mass.

    upd:

    If it's easier to say, we need analog like this on PHP:

    $array[num_1][] = [val_1 => val_2]
    $array[num_1][] = [val_3 => val_4]
    


  • Apparently, you just want to add a new characteristic with an object value, it's being implemented as follows.

    var obj = {
       num_1:{val_1: val_2}
    };
    

    obj['num_1']['val_3'] = val_4;

    result

    {
    num_1:
    {
    val_1: val_2,
    val_3: val_4
    }
    }




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2