Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Array Iteration Methods Array Manipulation Practice map()

Shafique Mohammed
seal-mask
.a{fill-rule:evenodd;}techdegree
Shafique Mohammed
Front End Web Development Techdegree Student 13,625 Points

I need help with map method on the daysOfWeek array, I'm trying to create a new array with abbreviated weekdays.

I need help with map method I am trying to create a new array to display abbreviated days of the week. The code I have produced the array is being displayed 7 times instead of one if anyone can help me would be a great help thanks in advance

app.js
const daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
let abbreviatedDays;

// abbreviatedDays should be: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
// Write your code below

abbreviatedDays = daysOfWeek.map(function(item, index, array) {
    // Return element for new_array

    return array = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
});

console.log(abbreviatedDay);

2 Answers

Thomas Nilsen
Thomas Nilsen
14,957 Points

Do you mean something like this?

const daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];

let abbreviatedDays = daysOfWeek.map(day => day.substr(0,3))

//This prints
//[ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ]
console.log(abbreviatedDays);