-
-
Save edinsoncs/418bce924841b3d72321 to your computer and use it in GitHub Desktop.
Javascript Map function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Map in javascripts | |
//map se pasa 3 parametros - currentValue, Index, Arr | |
function mapOne(){ | |
var miArray = [1, 2, 3]; | |
var incremento = 1; | |
miArray.map(function(multiplicar, indice, array){ | |
console.log('Muestro el indice de mi array' + indice); | |
console.log('Muestro mi array' + array); | |
return multiplicar * 2; | |
}); | |
} | |
//Usando Map genérico | |
//para usar generico se utiliza map.call(mivar, callback({})) | |
function mapTwo(){ | |
var nombre = "Edinson"; | |
[].map.call(nombre, function(devuelveTodo){ | |
if(nombre === "Edinson") { | |
return devuelveTodo; | |
} | |
}).reverse().join(); | |
var agregar = ':'; | |
var letters = ['Edinson', 'Richard', 'Luis', 'Ashly']; | |
[].map.call(letters, function(current, indice, arr){ | |
var ta = arr.slice(0, 2); | |
return ta; | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment