Answers for "find the matching property"

0

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';
});
Posted by: Guest on March-26-2020
0

find the property is matching

let wantedProperty = (arrayOfObjects.find(obj => obj.id === wantedObject.id) || {}).title || 'None Found';
Posted by: Guest on March-25-2020

Code answers related to "find the matching property"

Code answers related to "Javascript"

Browse Popular Code Answers by Language