“fungsi peta” Kode Jawaban

ES6 MAP USIN INDEX

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


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

console.log(map);
Graceful Grivet

fungsi peta

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

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

cara menggunakan metode peta dalam javascript

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

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

peta()

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

fungsi peta

# 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

fungsi peta

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

Jawaban yang mirip dengan “fungsi peta”

Pertanyaan yang mirip dengan “fungsi peta”

Lebih banyak jawaban terkait untuk “fungsi peta” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya