An electronic device comprising: a housing comprising a first portion, a second portion, and a third portion configured to be movable such that the second portion is capable of being folded with respect to the first portion; a first array antenna disposed at the first portion and comprising a first antenna element and a second antenna element; a second array antenna comprising a third antenna element and a fourth antenna element, and disposed at the second portion such that the third antenna element is aligned with the first antenna element and the fourth antenna element is aligned with the second antenna element when the electronic device is in a folded state in which the second portion of the housing is folded with respect to the first portion by using the third portion; a communication circuit electrically connected to the first array antenna and the second array antenna; and at least one processor, wherein the at least one processor is configured to: determine whether the electronic device is in an unfolded state or a folded state based on the second portion being in the unfolded state or folded state with respect to the first portion by using the third portion; when the electronic device is in the unfolded state, form a first beam through the first antenna element and the second antenna element or a second beam through the third antenna element and the fourth antenna element by using the communication circuit; and when the electronic device is in the folded state, form a third beam through the first antenna element and the third antenna element or a fourth beam through the second antenna element and the fourth antenna element by using the communication circuit. a housing comprising a first portion, a second portion, and a third portion configured to be movable such that the second portion is capable of being folded with respect to the first portion; a first array antenna disposed at the first portion and comprising a first antenna element and a second antenna element; a second array antenna comprising a third antenna element and a fourth antenna element, and disposed at the second portion such that the third antenna element is aligned with the first antenna element and the fourth antenna element is aligned with the second antenna element when the electronic device is in a folded state in which the second portion of the housing is folded with respect to the first portion by using the third portion; a communication circuit electrically connected to the first array antenna and the second array antenna; and at least one processor, wherein the at least one processor is configured to: determine whether the electronic device is in an unfolded state or a folded state based on the second portion being in the unfolded state or folded state with respect to the first portion by using the third portion; when the electronic device is in the unfolded state, form a first beam through the first antenna element and the second antenna element or a second beam through the third antenna element and the fourth antenna element by using the communication circuit; and when the electronic device is in the folded state, form a third beam through the first antenna element and the third antenna element or a fourth beam through the second antenna element and the fourth antenna element by using the communication circuit. when the electronic device is in the unfolded state, form a first beam through the first antenna element and the second antenna element or a second beam through the third antenna element and the fourth antenna element by using the communication circuit; and when the electronic device is in the folded state, form a third beam through the first antenna element and the third antenna element or a fourth beam through the second antenna element and the fourth antenna element by using the communication circuit.