find the matching property
var todos = [
{
item: 'Wash the dog',
added: 2018-03-22,
completed: false
},
{
item: 'Plan surprise party for Bailey',
added: 2018-03-14,
completed: false
},
{
item: 'Go see Black Panther',
added: 2018-03-12,
completed: true
},
{
item: 'Launch a podcast',
added: 2018-03-05,
completed: false
}
];
//Find the todo with the item of Go see Black Panther.
var item;
for (var i = 0; i < todos.length; i++) {
if (todos[i] === 'Go see Black Panther') {
item = todos[i];
break;
}
}
//or Array.find()
var item = todos.find(function (todo) {
return todo.item === 'Go see Black Panther';
});