JavaScript map

Ceren Susuz
1 min readJun 9, 2021

--

map (), kendisine parametre olarak gönderilen dizinin her bir elemanını belirlenen bir işleme tabi tutup, yeni bir dizi meydana getirir.

map (), kendisine parametre olarak gönderilen diziye herhangi bir müdahalede bulunmaz. O dizinin her elemanını belli bir işleme tabi tutarak yeni bir dizi meydana getirir.

Örneklerimizi outputları ile beraber inceleyelim.

*

let products = [

{id:1, name : “Acer Laptop”, unitPrice:15000},

{id:2, name : “Asus Laptop”, unitPrice:16000},

{id:3, name : “Hp Laptop”, unitPrice:13000},

{id:4, name : “Dell Laptop”, unitPrice:12000},

{id:5, name : “Casper Laptop”, unitPrice:17000},

]

/console.log(“<ul>”)

products.map(product=>console.log(`<li>${product.name}</li>`))

console.log(“</ul>”)

Output:

<ul>

<li>Acer Laptop</li>

<li>Asus Laptop</li>

<li>Hp Laptop</li>

<li>Dell Laptop</li>

<li>Casper Laptop</li>

</ul>

products.map(product=>{

console.log(product)

console.log(`<li>${product.name}</li>`)

})

Output:

{id: 1, name: “Acer Laptop”, unitPrice: 15000}

<li>Acer Laptop</li>

{id: 2, name: “Asus Laptop”, unitPrice: 16000}

<li>Asus Laptop</li>

{id: 3, name: “Hp Laptop”, unitPrice: 13000}

<li>Hp Laptop</li>

{id: 4, name: “Dell Laptop”, unitPrice: 12000}

<li>Dell Laptop</li>

{id: 5, name: “Casper Laptop”, unitPrice: 17000}

<li>Casper Laptop</li>

--

--

Ceren Susuz
Ceren Susuz

Written by Ceren Susuz

Software Developer at EMakina an EPAM Company

No responses yet