I am trying to return a value (ID), matching another field (Type) in the array.
Object array:
a: Array[3]
0: Object
1: Object
Desc: "Desc"
ID: "V000002"
Type: "SK"
__proto__: Object
2: Object
length: 3
find method:
ns.find = function (a) {
$.each( a, function (k, v) {
if (v.Type == 'SK') {
return v.ID
}
}
);
return "";
} ;
It doesn’t work even though there is a match. what’s wrong!
The
returnstatement inside ofjQuery.eachwon’t break out of yourns.findmethod, just the current loop iteration. To break out ofjQuery.each, you need to returnfalse;