ES6 -Karte 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
const array = [1, 2, 3, 4];
const map = array.map((x, index) => {
console.log(index);
return x + index;
});
console.log(map);
const arr = [{name: "test"}, {name: "test1"}, {name: "test2"}]
arr.map((n, i) => {
console.log(n);
})
const numbers = [1, 2, 3, 4, 5];
const bigNumbers = numbers.map(number => {
return number * 10;
});
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]
# 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.
const ratings = watchList.map(item => ({
title: item["Title"],
rating: item["imdbRating"]
}));