{"id":1209,"date":"2012-09-18T04:50:07","date_gmt":"2012-09-18T04:50:07","guid":{"rendered":"https:\/\/theextremewebdesigns.com\/blog\/?p=1209"},"modified":"2012-09-18T04:50:07","modified_gmt":"2012-09-18T04:50:07","slug":"jquery-comma-separated-list-make-comma-separated-list-of-array-values","status":"publish","type":"post","link":"https:\/\/theextremewebdesigns.com\/blog\/jquery-comma-separated-list-make-comma-separated-list-of-array-values\/","title":{"rendered":"jQuery Comma Separated List Examples"},"content":{"rendered":"<p>Sometime or the other, you may have worked with arrays in jQuery. And many times, you may have come across a situation where you need to <strong>show array values in a comma\u00a0separated\u00a0list<\/strong>, instead of just showing the individual array values. So do you know how to make \u00a0<strong>Comma Separated List<\/strong> ? In this article, I am going to share a solution to very easily<strong> <em>make comma separated list of array values using jQuery<\/em><\/strong>.<!--more--><\/p>\n<h2>Examples to Make Comma Separated List out of Array Value using jQuery<\/h2>\n<div class=\"make_demo\">\r\n\r\n\t<form action=\"https:\/\/theextremewebdesigns.com\/blog\/wp-content\/themes\/ewd_blog_2017\/try_demo.php?post_id=1209\" method=\"post\" name=\"form1\" target=\"_blank\" id=\"form1\">\r\n\r\n\r\n\t<input type=\"hidden\" name=\"shortcode_content\" id=\"shortcode_content\" value=\"\" \/>\r\n\r\n        <div class=\"try_demo_btn_container\">\r\n\r\n\r\n            <button type=\"submit\" name=\"sbt_make_demo\" id=\"sbt_make_demo\" class=\"btn-primary btn-try-demo\">\r\n                Try Demo\r\n            <\/button>\r\n\r\n\r\n        <\/div><!-- .try_demo_btn_container -->\r\n\r\n    <\/form>\r\n    <\/div>\r\n    \n<p>Let&#8217;s consider this with an example. Assume that we have set of checkboxes (array). Now we wish to use jQuery to make comma\u00a0separated\u00a0list from the values of the\u00a0checked checkboxes.<\/p>\n<h3>Example: Here is the full source code to make comma separated list out of array values using jQuery<\/h3>\n<pre class=\"lang:xhtml decode:true\">&lt;html&gt;\n&lt;head&gt;\n&lt;title&gt;jQuery Comma Separated List |Make Comma Separated List of Array values&lt;\/title&gt;\n&lt;script type=\"text\/javascript\" src=\"js\/jquery-1.8.2.min.js\"&gt;&lt;\/script&gt;\n&lt;\/head&gt;\n\n&lt;body&gt;\n&lt;p&gt;\n&lt;label&gt;\n&lt;input type=\"checkbox\" name=\"fruits[]\" class=\"fruits\" value=\"apple\" id=\"fruits_0\"&gt;\nApple&lt;\/label&gt;\n&lt;br&gt;\n&lt;label&gt;\n&lt;input type=\"checkbox\" name=\"fruits[]\" class=\"fruits\" value=\"mango\" id=\"fruits_1\"&gt;\nMango&lt;\/label&gt;\n&lt;br&gt;\n&lt;label&gt;\n&lt;input type=\"checkbox\" name=\"fruits[]\" class=\"fruits\" value=\"grapes\" id=\"fruits_2\"&gt;\nGrapes&lt;\/label&gt;\n&lt;br&gt;\n&lt;\/p&gt;\n\n&lt;input type=\"submit\" name=\"btn_alert\" id=\"btn_alert\" value=\"Alert Comma Seprated List\" \/&gt;\n\n&lt;script type=\"text\/javascript\"&gt;\n\n$(document).ready(function() {\n\n$('#btn_alert').click(function(){\n\nvar comma_separated_list = $(\".fruits:checked\").map(function() {\nreturn $(this).val();\n}).get().join();\n\nalert(comma_separated_list);\n\nreturn false;\n\n});\n\n});\n\n&lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n<p>When you run the above code, click on the button and that will give the <strong>comma separated list of the checked\u00a0checkboxes\u00a0values<\/strong>.<\/p>\n<div class=\"make_demo\">\r\n\r\n\t<form action=\"https:\/\/theextremewebdesigns.com\/blog\/wp-content\/themes\/ewd_blog_2017\/try_demo.php?post_id=1209\" method=\"post\" name=\"form1\" target=\"_blank\" id=\"form1\">\r\n\r\n\r\n\t<input type=\"hidden\" name=\"shortcode_content\" id=\"shortcode_content\" value=\"\" \/>\r\n\r\n        <div class=\"try_demo_btn_container\">\r\n\r\n\r\n            <button type=\"submit\" name=\"sbt_make_demo\" id=\"sbt_make_demo\" class=\"btn-primary btn-try-demo\">\r\n                Try Demo\r\n            <\/button>\r\n\r\n\r\n        <\/div><!-- .try_demo_btn_container -->\r\n\r\n    <\/form>\r\n    <\/div>\r\n    \n<h5>Simple, isn&#8217;t it?<\/h5>\n<p>Do you know of any other ways to <em><strong>make comma separated list of an array\u00a0using jQuery<\/strong><\/em>? Feel free to suggest by commenting below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometime or the other, you may have worked with arrays in jQuery. And many times, you may have come across a situation where you need to show array values in a comma\u00a0separated\u00a0list, instead of just showing the individual array values. So do you know how to make \u00a0Comma Separated List ? In this article, I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":395,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[20,13],"tags":[40,42,41],"class_list":["post-1209","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jquery-tips-and-tricks","category-tips-and-tricks","tag-jquery-2","tag-jquery-demos-2","tag-jquery-tips"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paBnQX-jv","jetpack_sharing_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/1209","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/comments?post=1209"}],"version-history":[{"count":0,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/1209\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/media?parent=1209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/categories?post=1209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/tags?post=1209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}