How to get the value found by indexOf?

0

I'm having a code where I pass a value and I need to check if this value exists within array , so I use indexOf . What I would like is to get the value that indexOf finds, for example:

org = 3;
var array_t = [1,2,3,4,5];

receb = (array_t.indexOf(org));

In this case it will show that 3 is in position 2 . What I want is to get the value 3 . It's possible?

    
asked by anonymous 21.11.2014 / 17:10

1 answer

5

Hmmm ... the value you pass to the method is the value that it finds (if it finds), so you already have the value you're looking for right?

But you can always do this (even if it's redundant):

org = 3;
var array_t = [1,2,3,4,5];
receb = array_t.indexOf(org);

var valorAchado = array_t[receb]; // dá 3
    
21.11.2014 / 17:14