Javatpoint Logo
Javatpoint Logo

jQuery toArray() method

The toArray() method is used to return all elements contained in the jQuery set as an array.

Syntax

This method does not accept any argument.

We can understand the use of the toArray() method using an example.

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

Output

jQuery toArray() method

After clicking the given button, an alert box will be displayed, as shown in the below screenshot.

jQuery toArray() method

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.






Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA