About js findIndex

Why does console come out as undefined?

var ages = [3, 10, 18, 20];

function zxc(data, dataArray){
    dataArray.findIndex(function(element){
        return element == data;
    });
}

console.log(zxc(18, ages))  //undefined

it"s no problem to write like this

    
    var ages = [3, 10, 18, 20];
    var zxc = ages.findIndex(function(element){
        return element == 18;
    });
    console.log(zxc)  //2
Apr.14,2022

The scope of

return is the most recent function
you are referring to

. The
  

function itself does not return a value

Menu