Array method.map()

Hello there, Need some help to crack up…

i am having doubt with array method.map() of iterator concept.

Here is my code.

const singers = [‘A’ , ‘B’ , ‘C’];

const best = singers.map(singer => {

singer + ‘best in pop industry’;

});

console.log(singers);

As i looked at map method it should executes A is the best in pop industry and other continues but while its printing [ ‘A’, ‘B’, ‘C’ ]

.map() creates a new array, which you store in best variable.

so if you want to see the best singers in the pop industry, you need to log best. There is also a small problem with your .map(), but i will leave that for you to figure out :slight_smile:

Okay stetim94, thankyou for response I will try it now and let you know.

Thanks a lot for your support.

Hi Stetim94, I rechecked the code again what you said is right log to ‘best’ and i changed singer to member keyword after making these changes it worked well and i understood the concept of map method which gives result as array by executing a call back function.

As a beginner to learn JS and understanding it takes time for me but now i am getting the hang of it. :slightly_smiling_face:

// Right Code
const singers = [‘A’ , ‘B’ , ‘C’];

const best = singers.map(member => {

return member + ’ great in the world.’;

});

console.log(best);

1 Like