Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if value exists in 2D array

I have a 2d array in the format

emi_309 | present | weak   | 6
emi_310 | present | strong | 9
emi_319 | present | medium | 8
emi_315 | present | weak   | 5

I want to check if a value exists in the first column using a simple function

E.g, check if emi_77 exists in the first column

I came across $.inArray(value, array) but this function is for a 1d array only.

Is there something similar for 2d array

like image 427
Kim Avatar asked Feb 11 '13 13:02

Kim


1 Answers

Yes, if you do a combination of $.inArray and $.map:

if ($.inArray(value, $.map(arr, function(v) { return v[0]; })) > -1) {
    // ...
}
like image 110
VisioN Avatar answered Oct 20 '22 00:10

VisioN