find the matching property

Solutions on MaxInterview for find the matching property by the best coders in the world

showing results for - "find the matching property"
Carolina
27 Sep 2018
1var todos = [
2	{
3		item: 'Wash the dog',
4		added: 2018-03-22,
5		completed: false
6	},
7	{
8		item: 'Plan surprise party for Bailey',
9		added: 2018-03-14,
10		completed: false
11	},
12	{
13		item: 'Go see Black Panther',
14		added: 2018-03-12,
15		completed: true
16	},
17	{
18		item: 'Launch a podcast',
19		added: 2018-03-05,
20		completed: false
21	}
22];
23
24//Find the todo with the item of Go see Black Panther.
25var item;
26for (var i = 0; i < todos.length; i++) {
27	if (todos[i] === 'Go see Black Panther') {
28		item = todos[i];
29		break;
30	}
31} 
32//or Array.find()
33
34var item = todos.find(function (todo) {
35	return todo.item === 'Go see Black Panther';
36});
Amina
30 Mar 2016
1let wantedProperty = (arrayOfObjects.find(obj => obj.id === wantedObject.id) || {}).title || 'None Found';