Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
how to use .map function in jquery?


What I have tried:

how to use .map function in jquery?
Posted
Updated 16-Aug-19 2:25am
Comments
Richard Deeming 14-Aug-19 5:58am    
This site does not charge you for each word you type. Help us to help you by providing a proper description of your question.

If you're just going to type the same terse sentence three times, then type it into Google's search box, not the "ask a question" box.

Quote:
how to use .map function in jquery?
The map function enables you to perform a function on each element of an array. So this,

JavaScript
var numbers = [ 1, 2, 3, 4, 5 ];
numbers = numbers.map(number => number + 10);
console.log(numbers);

// expected to be
// 11, 12, 13, 14, 15
It is similar to,
JavaScript
var numbers = [ 1, 2, 3, 4, 5 ];
for (var number in numbers) {
    numbers[number] = numbers[number] + 10;
}
console.log(numbers);
A little bit bizarre, but that is what it does. It lets you perform an action on each element, without having to worry about iterators, incremental variables, etc. Also it looks cleaner.

Check more here on MDN, Array.prototype.map() - JavaScript | MDN[^]
 
Share this answer
 
Process each element of an array or object to get a new array.

For array, each element is can be translated.

For object, it can be used to map an object key to an array.

Detail and example at jQuery documentation. jQuery.map() | jQuery API Documentation[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900