I have an object, let's say
var obj = [{"name": "banana", "type": "fruit"},
{"name": "carrot", "type": "vegetable"}];
And I need to add an object right after the first one [0] so I'll get the following:
var obj = [{"name": "banana", "type": "fruit"},
{"name": "apple", "type": "fruit"},
{"name": "carrot", "type": "vegetable"}];
needless to say I want it dynamic, and I'm trying to avoid loops for ease of use later down the road...
Is there any function like
obj.pushAfter(this['type'], "fruit", {"name": "apple", "type": "fruit"});
Type of function? P.S I'm using Jquery so that's an option