Funkcja mapy
const arr = [{name: "test"}, {name: "test1"}, {name: "test2"}]
arr.map((n, i) => {
console.log(n);
})
Code Sir
const arr = [{name: "test"}, {name: "test1"}, {name: "test2"}]
arr.map((n, i) => {
console.log(n);
})
const numbers1 = [45, 4, 9, 16, 25];
const numbers2 = numbers1.map(myFunction);
function myFunction(value, index, array) {
return value * 2;
}
const numbers = [1, 2, 3, 4, 5];
const bigNumbers = numbers.map(number => {
return number * 10;
});
let new_array = arr.map(function callback( currentValue[, index[, array]]) {
// return element for new_array
}[, thisArg])
//map() methods returns a new array
const data = {name: "laptop", brands: ["dell", "acer", "asus"]}
let inside_data = data.brands.map((i) => {
console.log(i); //dell acer asus
});
const myAwesomeArray = [5, 4, 3, 2, 1]
myAwesomeArray.map(x => x * x)
// >>>>>>>>>>>>>>>>> Output: [25, 16, 9, 4, 1]