kaniosrn-j
6/16/2018 - 5:45 PM

Find matches object Id - vanilla js

var objHasItems = [{
        id: 1,
        completed: true,
        itemName: 'milk',
        date: '2014-10-00'
    },
    {
        id: 2,
        completed: true,
        itemName: 'cookies',
        date: '2014-10-01'
    },
    {
        id: 3,
        completed: true,
        itemName: 'ice cream',
        date: '2014-10-02'
    }
];

let findById = function(id){
        for(var item in objHasItems){
            if( objHasItems[item].id === id ) {
            	// objHasItems[0/1/2]
                console.log(groceryService.objHasItems[item]);
                return groceryService.objHasItems[item];
            }
        }
    };