Search , insert and delete in an unsorted array | Function to implement search operation ; Driver program ; Using a last element as search element
function findElement ( arr , n , key ) { let i ; for ( i = 0 ; i < n ; i ++ ) if ( arr [ i ] == key ) return i ; return - 1 ; } let arr = [ 12 , 34 , 10 , 6 , 40 ] ; let n = arr . length ; let key = 40 ; let position = findElement ( arr , n , key ) ; if ( position == - 1 ) document . write ( " " ) ; else document . write ( " " + ( position + 1 ) ) ;