25
loading...
This website collects cookies to deliver better user experience
const drugs = ["facebook", "whatsapp", "instagram"]
// map
const newDrugs = drugs.map(function(value){
return "the " + value;
})
//console newDrugs
["the facebook", "the whatsapp", "the instagram"]
// map
const newDrugs = drugs.map(value => "the ")
const newDrugs = drugs.map(function(element){
return "the " + element;
})
const newDrugs = drugs.map(function(element, index){
console.log(index) //console 0, 1, 2
return "the " + element;
})
const newDrugs = drugs.map(function(element, index, array){
console.log(index)
console.log(array) //console every time ["facebook", "whatsapp", "instagram"]
return "the " + element;
})
const newDrugs = drugs.map(function(element){
return "the " + element + " by " + this.ceo;
}, {
ceo: 'mark zuckerburg',
})
//console
["the facebook by mark zuckerburg", "the whatsapp by mark zuckerburg", "the instagram by mark zuckerburg"]
const ourArray = [{key: 1, value: 10},
{key: 2, value: 20},
{key: 3, value: 30}]
let reformattedArray = ourArray.map(x => {
let newObj = {}
newObj[x.key] = x.value
return newObj
})
// reformattedArray is now [{1: 10}, {2: 20}, {3: 30}],