$ ("P"). Append ($ ("input"). Map (function () {return $ (this). Val (); }). Get (). Join (","));
<form> <input type= "text" name= "name" value= "John" > <input type= "text" name= "password" value= "password" > <input type= "text" name= "url" value= "http://ejohn.org/" ></form>
This is a example I took from the official website.
I was very confused, do not understand why in the map method is called after a get method. In theory, the data returned by map should be an array (collection). You can directly call the Join method to convert to string.
Read the documentation carefully and find articles here.
I originally confused the JavaScript object/array (actually DOM) and Jqeruy Object/array these two concepts
In fact, JavaScript objects and arrays are not mutually identifiable with jquery.
When I found out about this "secret", I figured out why I needed the Get method.
. Get (): Retrieve the DOM elements matched by the JQuery object.
This is the definition of the official website. is to convert the jquery object to a DOM object. All DOM objects can be used by JavaScript. Here jquery is actually a smooth transition through the get mechanism.
So let's look back at the example above
Map returns the jquery array and then passes the get method to the JavaScript Dom array. The last call to the Join method becomes a string.
This article is from the "Development" blog, make sure to keep this source http://jamesdev.blog.51cto.com/2066624/1774930
jquery map calls the Get () method confused