So I have a array of items which looks like this:
var receivedQuery = [ { 'ingredients.ingredient': /^what$/i },
{ 'ingredients.ingredient': /^you$/i},
{ 'ingredients.ingredient': /^said$/i},
{ 'ingredients.ingredient': /^about$/i},
{ 'ingredients.ingredient': /^that$/i}
];
and I'm trying to log in console each item in array , and the rest of array without that current item in it with for loop. And I tried to do so with splice method like this:
var splicedQuery = receivedQuery;
for (i = 0, max = receivedQuery.length; i < max; i++) {
var position = i;
splicedQuery = splicedQuery.splice(position, 1);
console.log( receivedQuery[i], splicedQuery );
};
but I'm not receiving it as I wanned to:
{ 'ingredients.ingredient': /^you$/i } [ { 'ingredients.ingredient': /^what$/i } ]
{ 'ingredients.ingredient': /^said$/i } []
{ 'ingredients.ingredient': /^about$/i } []
{ 'ingredients.ingredient': /^that$/i } []
undefined []
and I want it to output something like this:
{ 'ingredients.ingredient': /^what$/i }, [ { 'ingredients.ingredient': /^you$/i}, { 'ingredients.ingredient': /^said$/i}, { 'ingredients.ingredient': /^about$/i}, { 'ingredients.ingredient': /^that$/i} ]
{ 'ingredients.ingredient': /^you$/i }, [ { 'ingredients.ingredient': /^what$/i}, { 'ingredients.ingredient': /^said$/i}, { 'ingredients.ingredient': /^about$/i}, { 'ingredients.ingredient': /^that$/i} ]
{ 'ingredients.ingredient': /^said$/i }, [ { 'ingredients.ingredient': /^what$/i}, { 'ingredients.ingredient': /^you$/i}, { 'ingredients.ingredient': /^about$/i}, { 'ingredients.ingredient': /^that$/i} ]
........
I'm not sure exactly how to do it do console it it right way... what is the best method? Maybe to use something else than splice()
or?
You can see and edit my situation in jsfiddle to: http://jsfiddle.net/RgGzE/