Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, I'm seeing that quite a few people are interested in this so here's what I have up to now:</p> <pre><code>var filter = function(what,where) { var sameArrays = function(arr,arr1) { var al = arr.length, bl = arr1.length; if (al !== bl || al === 0 || bl === 0) { return; } for (var i = al - 1; i &gt;= 0; i--){ if (!match(arr[i], arr1[i])) { return; } } return arr1; }; var sameObjects = function(obj,obj1) { for (var i in obj) { if(!obj1.hasOwnProperty(i)){return;} if (!match(obj[i],obj1[i])) {return;} } return obj1; }; var inArray = function(value,obj) { var r = [], m = match; for (var i = obj.length - 1; i &gt;= 0; i--){ var item = obj[i]; if( m(value,item) ) { r.push( item ); } }; return (r.length) ? r : undefined ; }; var inObject = function(value,obj) { var r = [], m = match; for(var i in obj){ var item = obj[i]; if( m(value,item) ) { r.push( item ); } }; return (r.length) ? r : undefined ; }; var inString = function(value,string) { var valueConstructor = value.constructor; if( valueConstructor === RegExp) { return (value.test(string)) ? string : undefined ; } else if( valueConstructor === Function &amp;&amp; value(string) === true ) { return string; } }; var match = function(a,b) { if(typeof a === 'undefined' || typeof b === 'undefined' || a === null || b === null) { return; } if (a == b) { return b;} var vc = a.constructor, oc = b.constructor; // Cannot compare array or object to a string or a number if( (vc === Array || vc === Object) &amp;&amp; (oc === String || oc === Number) ) { return; } if( oc === Array &amp;&amp; vc === Array ) { return sameArrays(a,b); } else if(oc === Array) { return inArray(a,b); } else if (oc === Object &amp;&amp; vc === Object) { return sameObjects(a,b); } else if (oc === Object) { return inObject(a,b); } else if (vc === Object || vc === Array) { return; } else if (oc === String || oc === Number){ return inString(a,b); } }; return match(what,where); }; </code></pre> <p>Which allows you do the following:</p> <pre><code>var b = [ { 'name' : 'some name', age: 23, id: 0, 'has' : ['dogs'] }, { 'name' : 'some name 2', age:24, id: 1, 'has' : ['dogs', 'cats'] }, { 'name' : 'some name 3', age: 25, id: 2 , 'has' : ['donkeys', 'goats']}, { 'name' : 'some name 4', age:26, id: 3, 'has' : ['parrots', 'treasure'] }, { 'name' : 'some name 5', age:27, id: 4, 'has' : undefined } ]; filter({ age:23 },b) filter({ age:'24' },b) filter({ name: /\d$/ },b) filter('dogs',b) filter({ has: 'goats' },b) </code></pre> <p>This is part of some sort of js library that I've been working on, so if you find working with json + dom try searching google code for <strong>jdatastore</strong>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload