So I have an array of objects;
[
{
"foo": 2,
"bar": "test"
},
{
"foo": 19,
"bar": "value"
},
{
"foo": 7,
"bar": "temp"
}
]
I need to move an object with a particular value of foo
to the beginning of the array. The value is always in the object, but there's no guarantee the object will be in the array.
So after running moveToFront(19);
for instance, I'd have the following:
[
{
"foo": 19,
"bar": "value"
},
{
"foo": 2,
"bar": "test"
},
{
"foo": 7,
"bar": "temp"
}
]
How would I go about doing this?