jQuery toArray() method
The toArray() method is used to return all elements contained in the jQuery set as an array.
This method does not accept any argument.
We can understand the use of the toArray() method using an example.
In this example, we are using the toArray() method to convert the paragraphs into an array. On clicking the given button, the paragraph elements will be converted to an array, and an alert box will display that shows the innerHTML of the paragraph elements.Test it Now
After clicking the given button, an alert box will be displayed, as shown in the below screenshot.
Similarly, three more alert boxes will be displayed by clicking the OK button in the alert box. This is because there are four paragraph elements in the program.