“JS Map ()” Kod odpowiedzi

Jak używać metody map w JavaScript

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

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

mapa()

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

Mapa w JS

//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
});
D@RK$T@R

array.map

let arr = [1,2,3]

/*
  map accepts a callback function, and each value of arr is passed to the 
  callback function. You define the callback function as you would a regular
  function, you're just doing it inside the map function
  
  map applies the code in the callback function to each value of arr, 
  and creates a new array based on your callback functions return values
*/
let mappedArr = arr.map(function(value){
	return value + 1
})

// mappedArr is:
> [2,3,4]
QuietHumility

JS Map ()

var number = [1, 2 , 3, 4, 5, 6, 7, 8, 9]; 
var doubles  = number.map((n) => { return n*2 })

/*  doubles 
    (9) [2, 4, 6, 8, 10, 12, 14, 16, 18] */
ofroog

Mapa JavaScript

const items = [1, 2, 3, 4, 5, 6, 7, 8, 9];

const anotherItems = items.map(item => item * 2);

console.log(anotherItems);
Azizul7m

Odpowiedzi podobne do “JS Map ()”

Pytania podobne do “JS Map ()”

Więcej pokrewnych odpowiedzi na “JS Map ()” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu