The Extract Variable refactoring puts the result of the selected expression into a variable. It declares a new variable and uses the expression as an initializer. The original expression is replaced with the new variable.
Extract a variable in-place
In the editor, select the expression to be replaced with a variable.
Press Control+Alt+V or selectfrom the context menu.
If more than one occurrence of the selected expression is found, select Replace this occurrence only or Replace all occurrences in the popup.
Specify the name of the variable. You can choose from the list of suggestions or set another name.
If you want to apply automatic type declaration for the variable, set the Declare auto checkbox.
When applicable, you can also declare a variable as
constby setting Declare const: