Answer the question
In order to leave comments, you need to log in
How to iterate through an array of objects, select a certain property, change it, and return the new value of that property to the array?
there is an array of objects
var tasks = [{
name: "Задача № 1",
selectedProject: 'select project',
dateBegin: new Date('07 24, 2016 19:58:49'),
dateFinish: new Date('07 24, 2016 19:58:59')
}, {
name: "Задача № 2",
selectedProject: 'timer',
dateBegin: new Date('07 25, 2016 19:58:30'),
dateFinish: new Date('07 25, 2016 19:59:15')
}]
localStorage.setItem("tasks", JSON.stringify(newTasks));
var newTasks = JSON.parse(localStorage.getItem("tasks"))
for(var i=0; i < newTasks.length; i++)
new Date(Date.parse(newTasks[i].dateBegin));
for(var i=0; i < newTasks.length; i++)
new Date(Date.parse(newTasks[i].dateFinish));
Answer the question
In order to leave comments, you need to log in
Well, it became
for(var i=0; i < newTasks.length; i++)
newTasks[i].dateBegin = new Date(Date.parse(newTasks[i].dateBegin));
Array. map
var names = ['HTML', 'CSS', 'JavaScript'];
var nameLengths = names.map(function(name) {
return name.length;
});
// получили массив с длинами
alert( nameLengths ); // 4,3,10
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question