Link for all dot net and sql server video tutorial playlists
https://www.youtube.com/user/kudvenka...
Link for slides, code samples and text version of the video
http://csharp-video-tutorials.blogspo...
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.
/ @aarvikitchen5572
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
On this page of the site you can watch the video online jQuery map method with a duration of hours minute second in good quality, which was uploaded by the user kudvenkat 21 April 2015, share the link with friends and acquaintances, this video has already been watched 68,064 times on youtube and it was liked by 310 viewers. Enjoy your viewing!