Reputation: 47
I am trying to return object from function but it returns nothing any idea?
var todo = [{
id: 'a01',
titre: 'Citation',
message: 'Vous êtes de ceux-là ? Ca tombe bien, je lai été moi aussi !',
completed: false
}];
getById: function(todoId) {
for (var i = 0; i < todo.length; i++) {
if (todo[i].id == todoId) {
return todo;
}
}
}
Upvotes: 1
Views: 97
Reputation: 877
Try this code:
var todo=[{
id:'a01',
titre:'Citation',
message:'Vous êtes de ceux-là ? Ca tombe bien, je lai été moi aussi !',
completed:false
}];
var getById = function(todoId){
for(var i=0;i<todo.length;i++){
//console.log(todo[i].id == todoId);
if(todo[i].id == todoId){
return todo[i];
}
}
}
Upvotes: -1
Reputation: 8080
return the array element instead of the complete array:
getById: function(todoId){
for(var i=0;i<todo.length;i++){
//console.log(todo[i].id == todoId);
if(todo[i].id == todoId){
return todo[i];
}
}
}
Upvotes: 2