Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Javascript using .map() loop to loop through an array

// Durations are in minutes 
const tasks = [
  {
    'name'     : 'Write for Envato Tuts+',
    'duration' : 120
  },
  {
    'name'     : 'Work out',
    'duration' : 60
  },
  {
    'name'     : 'Procrastinate on Duolingo',
    'duration' : 240
  }
];
const task_names = tasks.map(function (task, index, array) {
    return task.name; 
});

console.log(task_names) // [ 'Write for Envato Tuts+', 'Work out', 'Procrastinate on Duolingo' ]
Source by code.tutsplus.com #
 
PREVIOUS NEXT
Tagged: #Javascript #loop #loop #array
ADD COMMENT
Topic
Name
3+9 =