Reputation: 962
I'm having trouble getting a splice to work.
I have an array, that I push objects into...
one of the 'properties' on these objects Im pushing is an array (with me so far?):)
quick example:
var userPicks = [];
userPicks.push({casename:caseName, fullname:fullName, trialdate:trialDate, citystate:cityState, plaintiff:plaintiff, itemsordered:itemsOrdered=[{name:itemOrdered, price:itemPrice}]});
this all works fine and dandy... I can push things in.. access them and see the correct data in console (FireBug)
but when I try to splice something.. I get an error in FireBug/console..
TypeError: userPicks[i].itemsordered[x].splice is not a function
However, I can add things to the 'sub-array' (I'll refer to it as...the itemsorderd[x] array).. access/read them as well...??
console.log("Name Check: "+userPicks[i].itemsordered[x].name); //works
userPicks[i].itemsordered.push({name:itemOrdered, price:itemPrice}); //works
but the splice isnt working?
What am I missing? syntax error somehow?
PLEASE!,, only answer if you want to provide 'help'.. not to just inform me your dont know or have time to help.
I cant seem to SPLICE() the array that is in the object property.. (although pushing, and accessing/read to same array is fine)
all 'real' help is appreciated!
Thanks.
Upvotes: 0
Views: 2129
Reputation: 636
You are trying to call splice on an object not an array:
userPicks[i].itemsordered
is the arrayuserPicks[i].itemsordered[x]
is an object inside the array, not an array itself.You want to call splice on userPicks[i].itemsordered
, i.e:
userPicks[i].itemsordered.splice(...)
Upvotes: 1