I am trying to return the next item in the array, that is the element that is next in the index so if I use 7 as an example a below I need to return 8.
nums = [5, 3, 7, 8, 1, 10];
num = 7;
const result = nums.find(number =>{
if(num === number) // how do I return index+1 here?
});
so for this example I need to return 8 as this is the next item after 7. Is this possible to do with find?
>Solution :
You should use indexOf
nums = [5, 3, 7, 8, 1, 10];
num = 7;
const indexOfNum = nums.indexOf(num);
const result = nums[indexOfNum + 1]