“Fonction de cartographie” Réponses codées

index de la carte ES6

const array = [1, 2, 3, 4];


const map = array.map((x, index) => {
  console.log(index);
  return x + index;
});

console.log(map);
Graceful Grivet

Fonction de cartographie

const arr = [{name: "test"}, {name: "test1"}, {name: "test2"}]

arr.map((n, i) => {
	console.log(n);
})
Code Sir

Comment utiliser la méthode de la carte en javascript

const numbers = [1, 2, 3, 4, 5]; 

const bigNumbers = numbers.map(number => {
  return number * 10;
});
TechWhizKid

carte()

The map() method creates a new array populated with the results of calling 
a provided function on every element in the calling array.

const array1 = [1, 4, 9, 16];

// pass a function to map
const map1 = array1.map(x => x * 2);

console.log(map1);
// expected output: Array [2, 8, 18, 32]
CodeMaster64

Fonction de cartographie

# map function
city_lengths = map(len, ['sanjose', 'cupertino', 'sunnyvale', 'fremont'])
print(list(city_lengths))

# [7, 9, 9, 7]
# Map takes a function and a collection of items. It makes a new, empty collection, runs the function on each item in the original collection and inserts each return value into the new collection. It returns the new collection.
Impossible Impala

Fonction de cartographie

const ratings = watchList.map(item => ({
  title: item["Title"],
  rating: item["imdbRating"]
}));
Perfect Peccary

Réponses similaires à “Fonction de cartographie”

Questions similaires à “Fonction de cartographie”

Plus de réponses similaires à “Fonction de cartographie” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code