“Mapa tablicy” Kod odpowiedzi

Mapa tablicy JavaScript ()

const numbers1 = [45, 4, 9, 16, 25];
const numbers2 = numbers1.map(myFunction);

function myFunction(value, index, array) {
  return value * 2;
}
naly moslih

tablica mapa MDN

let new_array = arr.map(function callback( currentValue[, index[, array]]) {
    // return element for new_array
}[, thisArg])
Bad Bison

tablice map

function map(array, transform) {
  let mapped = [];
  for (let element of array) {
    mapped.push(transform(element));
  }
  return mapped;
}

let rtlScripts = SCRIPTS.filter(s => s.direction == "rtl");
console.log(map(rtlScripts, s => s.name));
// → ["Adlam", "Arabic", "Imperial Aramaic", …]
Xanthous Xenomorph

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

Mapa tablicy

$catIds = array_map(function($o) { return $o->id;}, $objects);
calyCoder

array.map

var x = [1,2,3,4].map( function(item) {return item * 10;});
Outstanding Otter

Odpowiedzi podobne do “Mapa tablicy”

Pytania podobne do “Mapa tablicy”

Więcej pokrewnych odpowiedzi na “Mapa tablicy” w PHP

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

Przeglądaj inne języki kodu