How to get the row added by ajax in the right place?
I finally made it work this way:
  public function ajaxAddRow(array &amp;$form, FormStateInterface $form_state)
  {
    $myKey = $form_state-&gt;getTriggeringElement()['#name'];
    $formBis = [];
    foreach ($form as $key =&gt; $value) {
      switch ($key) {
        case 'subscriptions':
          foreach ($form['subscriptions'] as $key2 =&gt; $value2) {
            $formBis['subscriptions'][$key2] = $form['subscriptions'][$key2];
            if (is_numeric($key2)) {
              if ($key2 == $myKey) {           &lt;&lt; Here is the row to be copied
                $keyfornewrow = $key2 + 5;
                $formBis['subscriptions'][$keyfornewrow] = $form['subscriptions'][$key2];
                foreach ($formBis['subscriptions'][$keyfornewrow] as $key3 =&gt; $value3) {
                    &lt;&lt; some code here to initialize content of copied row &gt;&gt;
                }
              }
            }
          }
          break;
        default:
          $formBis[$key] = $form[$key];
      }
    }
    return $formBis;
  }