Summary
Keywords
Full Transcript
Link for all dot net and sql server video tutorial playlists https://www.youtube.com/user/kudvenkat/playlists?sort=dd&view=1 Link for slides, code samples and text version of the video http://csharp-video-tutorials.blogspot.com/2015/04/jquery-map-method.html Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help. https://www.youtube.com/channel/UC7sEwIXM_YfAMyonQCrGfWA/?sub_confirmation=1 In this video we will discuss jQuery map method Just like jquery each() method, map() method is also used to iterate over matched elements. However, there are some differences between map() and each() methods which we will discuss in our next video. In general, if you want to create an array or concatenated string based on all matched elements in a jQuery selector, it is better to use map() over each() method. Replace < with LESSTHAN symbol and > with GREATERTHAN symbol Consider the following HTML <ul> <li>US</li> <li>India</li> <li>UK</li> <li>Canada</li> <li>Australia</li> </ul> To create an array of list item text values, we could use either map() or each() methods. Using each() method $(document).ready(function () { var result = []; $('li').each(function (index, element) { result.push($(element).text()); }); alert(result); }); Using map() method $(document).ready(function () { alert($('li').map(function (index, element) { return $(element).text(); }).get()); }); To create a pipe delimited string of all list item text values, we could use either map() or each() methods. The output should be as shown below. US|India|UK|Canada|Australia ` Using each() method $(document).ready(function () { var result = ''; $('li').each(function (index, element) { result += $(element).text() + "|"; }); result = result.substr(0, result.length - 1); alert(result); }); Using map() method $(document).ready(function () { alert($('li').map(function (index, element) { return $(element).text(); }).get().join('|')); }); In our next video, we will discuss the differences between map and each methods and when to use one over the other
