Array.Map Flashcards
var array1 = [1, 4, 9, 16];
const test = array1______(x => x * 2);
console.log(test); // expected output: Array [2, 8, 18, 32]
.map
var array1 = [1, 4, 9, 16];
// pass a function to map const map1 = \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
console.log(map1); // expected output: Array [2, 8, 18, 32]
array1.map(x => x * 2);
var array1 = [1, 4, 9, 16]; const map1 = array1.\_\_\_\_\_\_\_(x => x * 2);
// expected output: Array [2, 8, 18, 32]
Map
var array1 = [1, 4, 9, 16]; const map1 = array1.map(x => x * 2);
console.log(map1==array1);
false
The ________method creates a new array with the results of calling a provided function on every element in the calling array.
map()
var nums = [ 5, 9, 7 ];
//WRITE .MAP THAT ADDS 1 TO EACH NUMBER var oneBetterThanNums =
var oneBetterThanNums = nums.map(function (num) { return num + 1; });
Use the map method on the daysOfWeek array, creating a new array of abbreviated week days. Each abbreviated string should be the first three letters of the long version in daysOfWeek. Store the new array in the variable abbreviatedDays.
const daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; let abbreviatedDays;
let abbreviatedDays = daysOfWeek.map(day => day.slice(0,3))
_________— executes a provided function once for each array element.
__________— creates a new array with the results of calling a provided function on every element in the calling array.
forEach()
map()
When we need to iterate and return the data for each element – we can use ________.
map
const authors = [ { firstName: "Beatrix", lastName: "Potter" }, { firstName: "Ann", lastName: "Martin" }, { firstName: "Beverly", lastName: "Cleary" }, { firstName: "Roald", lastName: "Dahl" }, { firstName: "Lewis", lastName: "Carroll" } ]; let fullAuthorNames;
// fullAuthorNames should be: ["Beatrix Potter", "Ann Martin", "Beverly Cleary", "Roald Dahl", "Lewis Carroll"] // Write your code below
authors. map((authors)=> ${authors.lastName} + ${authors.firstName}
);
console. log(fullAuthorNames);
//FIX THIS CODE
const authors = [ { firstName: "Beatrix"}, { firstName: "Ann",}, ];
const user = userNAmes.map(name=> {name : name})
(name=> ({name : name}))
add pertness to object literal
only with arrow functions