Currently, I am focusing on JavaScript and I have the task of finding the index of an element in an array.
const tasks = [{taskno:'1', todo:'cooking'},{taskno:'2', todo:'play'}];
My goal is to locate the index of the task with 'cooking' as its todo value, without knowing its task number. Is there a built-in function for this purpose?
I attempted to use the following code but it did not yield the desired result:
const index = tasks.indexOf({todo: 'cooking'});
Currently, I am resorting to using a for loop for this task. Are there any alternative methods available?
Your assistance is greatly appreciated :)