arrays


localstorage initially returns assigned type, then type Object


I am developing a shopping cart which enables users to add items of type "Product" to basket. When an item is initially added it is of type "Product", however when another item(second item) is added to the Array() array, it is of type "Object" from then on. This may not make a lot of difference during manipulation, however i'd rather keep the types consistent. Someone please point out where im going wrong, much appreciated.
constructor(private _http: Http) {
localStorage.setItem("cart", JSON.stringify(new Array<Product>()));
}
GetCartProducts() {
let storage:string = localStorage.getItem("cart");
return <Array<Product>>((storage) ? JSON.parse(storage) : new Array<Product>());
}
AddProduct(product: Product) {
let items = <Array<Product>>this.GetCartProducts();
console.log(items);
items.push(<Product>product);
console.log(items);
localStorage.setItem("cart", JSON.stringify(<Array<Product>>items));
}


Related Links

Hash with array in value
How to get the length of a report's GroupingLevel array in VBA
Q2: AttributeError: 'builtin_function_or_method' object has no attribute 'size'
How can I make the following code into a 2D array?
How to write from an array to another array in excel vba
How to store variables from loop to a file
Add a new value to array
Segmentation fault with array indexing in Fortran
Printing a ruby array with zero formatting
how to store a list in a single array index
Minizinc: create an array of int pairs
Given an array of integers, where every number appears thrice except one number appears twice, find the number that appears twice?
How to match value against array and set variables?
Empty array using scan functrion ruby
How to reference hash.values created array
Add an Array of length x to value in key : value hash using Ruby

Categories

HOME
security
symfony
openssl
vhdl
facebook-graph-api
jbehave
otrs
computer-vision
transparent
apollo
terrain
xtext
quill
websphere-liberty
nodemailer
subquery
shipping
flann
opera-mini
thumbnails
multiple-columns
autolayout
countif
logarithm
csh
skmaps
mef2
excel-2013
metadata-extractor
classpath
solidworks
pep8-assembly
ipfw
spring-insight
canvasjs
modelandview
body-parser
qtablewidget
hashcat
mms
zero
haskell-pipes
installshield-2012
tic-tac-toe
infusionsoft
soundjs
cross-entropy
paho
ttcn
cppunit
catia
email-parsing
lirc
w3-total-cache
istorage
spell-checking
cgcontext
execl
static-code-analysis
ingres
laravel-query-builder
sqldatareader
gulp-typescript
svn-merge
build-process
atlassian-crowd
visible
dts
database-backups
shipitjs
qt-linguist
axes
getrusage
schtasks.exe
application-loader
wikitext
matcaffe
kendo-menu
sem
android-snackbar
subresource-integrity
team-build
harp
xaml-designer
ember-cli-addons
virus
symfony-2.6
microblaze
fragment-tab-host
docopt
libssh2
alpha-transparency
phpdocx
sgml
circos
hamsterdb
cling
sql-server-2012-web
stagefright
fileconveyor
template-haskell
lync-server-2010
autostart
plone-funnelweb
gjs
makefile-project
v4l
surf
datacontract
serp
gtk2hs
dcpu-16
adsl
junit3
server-error
pivotal-crm
surefire
unreachable-code
linfu
code-design





Mobile Apps Dev
Database Users
javascript
java
csharp
php
android


MS Developer
developer works
python
ios
c
html
jquery


RDBMS discuss