Skip to content

Instantly share code, notes, and snippets.

View goldcoast's full-sized avatar
:atom:

Tait goldcoast

:atom:
  • Morningstar, Welab
  • shenzhen china
View GitHub Profile
//return an array of objects according to key, value, or key and value matching
function getObjects(obj, key, val) {
var objects = [];
for (var i in obj) {
if (!obj.hasOwnProperty(i)) continue;
if (typeof obj[i] == 'object') {
objects = objects.concat(getObjects(obj[i], key, val));
} else
//if key matches and value matches or if key matches and value is not passed (eliminating the case where key matches but passed value does not)
if (i == key && obj[i] == val || i == key && val == '') { //