Javatpoint Logo
Javatpoint Logo

jQuery makeArray() method

As the name implies, the makeArray() method is used to convert an array-like object into the true JavaScript array. It returns the array.

Syntax

This method accepts a single parameter, which is defined as follows -

obj - It is any object to turn into a native array.

Let's understand the working of the makeArray() method, using some illustrations.

Example1

In this example, we are using the makeArray() method to turn a collection of HTML elements into an array of items. We can use the isArray() method to check whether the elements are converted into an array or not. If the isArray() method returns true, the elements are converted into an array, otherwise not.

We can also use the jQuery type() method to check the type of the variable arr.

Test it Now

Output

After the execution of the above code, the output will be -

jQuery makeArray() method

After clicking the given button, the output will be -

jQuery makeArray() method

Example2

Here, we are using the makeArray() method to convert an array-like string arr into an array. The result of the conversion will be stored in the variable arr1. So, we are also using jQuery.type() method to check the type of the variable arr1.

In the output, we can see that the type of the variable arr1 is written as an array, and the value of the string is also converted into an array.

Test it Now

Output

After the execution of the above code, the output will be -

jQuery makeArray() method

After clicking the given button, the output will be -

jQuery makeArray() method




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