JSFiddle - React, Tailwind, and code Playground

by ilyabezp

JavaScript

myArray = [{'id':'73','foo':'bar'},{'id':45,'foo':'bar'},{'id':45,'foo':'bar'},{'id':46,'foo':'barggg'}];

var indexForxyz = {
    a:function(a,b){
    return $.grep(a,function(e){ return e['id'] == b });
    },
    i:function(a,b){
    return this.a(a,b).length>0?true:false;
    },
    g:function(a,b,c){
    if(!c)c='id';
    return this.a(a,b)[0][c];
    }
}

//var c = {'id':'73','foo':'bar'};
//alert(c['id']);

alert(indexForxyz.i(myArray,46));
alert(indexForxyz.g(myArray,46,'foo'));

//if(indexForxyz(myArray,46))var b = ;
var result = $.grep(myArray, function(e){ return e.id == 46; });
//alert(result);