Finding the index of the minimum value of an array

I have an array say ‘x’

I have to find the value of the index of the minimum value of this index, I’ve been trying to use the find_index but I keep running into an error, can you please help me with this

int x;
int y[$];

y = x.find_index with (item ==x.min());

Will this work ?

In reply to uvm_va_1:

The return type of min function is unpacked, we can not compare packed data type(here item) with unpacked data type. We can do as below



module test();
  
  int x [] = {13,41,89,31,2,67,2};
  
  int q[$];
  int y[$];
  
  
  initial
    begin
      y = x.min;
      foreach(y[i])
             q = x.find_index with(item == y[i]);
      $display("%p",q);
    end
endmodule

Regards,
Shanthi V A
www.maven-silicon.com

In reply to shanthi:

You can also do this one step:
q = x.find_index with(item == int’(x.min()));