The jquery map method is used as an example

  • 2020-03-30 02:42:48
  • OfStack

JQuery. Map (array, callback(elementOfArray, indexInArray))

Returns: an Array

Feel the jquery map method is very useful, I would like to share with you.

Method replaces an array or a single object with new content.
Example of an application: get a set of checkbox values, separated by English commas, and splice them.

<script type="text/javascript" src=""></script> 
var str = $(":checked").map(function(){ 
return this.value; 
<input type="checkbox" value="a"/>a 
<input type="checkbox" value="b"/>b 
<input type="checkbox" value="c"/>c 
 Results: <span/> 

In CSDN code editor, dare not flatter really, I'm jsFiddle created the above example, attached to the link:

Related articles: