I have a small problem regarding Array to find Elements using find() with findIndex. I have demo code which is worked when I am using only find() method with my array variable.
var a = [{
_id: 'newlead',
count: 45
}, {
_id: 'contact',
count: 12
}, {
leadCount: [{
_id: 'newlead',
count: 45
}, {
_id: 'contact',
count: 12
}]
}]
var findElement = a.find(a => {
return a._id === 'newlead'
});
console.log(findElement);
The actual problem is I want to check in an array, 'leadCount' is exist or not, if exist then I am doing this, I have a code. this code throws an error "TypeError: a.findIndex(...).find is not a function
let data = a.findIndex( element => {
return 'leadCount' in element
}).find(e => {
return e._id === 'newlead'
})
console.log(data)
Please suggest me the right thing.
thank you
findIndexinstead offind?{ _id: 'newlead', count: 45 }