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

Excel Array - Multiple Match Index - Not detecting one Criteria
spark scala typesafe config safe iterate over value of a specific column name
Efficient way of computing the Greatest Common Divisor from an Array - Swift [duplicate]
Read from array1 write from array2
Type Mismatch in Array
Subtracting from each element in array in python
C# Problems importing a file to an array and put each character in it's own index
How to identify the position of a sequence of elements in an array in bash
Combine values of two arrays to form key and values to hash in ruby [duplicate]
Create array with key from dict with sorted by dict values
How do I convert every element in an array to its own array?
Adding a list to an array from different file format in perl
How to use Perl `sort` and `pairwise` if I already have variables `$a` and `$b`
Sum dynamic part of array values Excel VBA
Ada How to get input a list of integer from a user and put it into an array
count occurences in for loop

Categories

HOME
converter
sas
security
ember.js
sass
jar
wmic
bing
youtube-livestreaming-api
amazon-product-api
zend-framework2
search-engine
jrebel
avl-tree
xamarin-studio
sign
mod-pagespeed
scaling
uicollectionview
internet-explorer-8
flexlm
rails-activerecord
jquery-form-validator
iup
non-deterministic
osmdroid
vcard
dd-wrt
pitest
bxslider
ifstream
gettext
superpowered
hashcat
ksoap
vsts-package-management
elfinder
concrete5-5.7
control-flow-graph
stereo-3d
bids
automator
fqdn
azure-availability-set
chrome-remote-desktop
android-bitmap
nuget-server
sqlexception
iron.io
sqldatareader
gulp-typescript
build-process
glkit
children
database-backups
clob
squirrel
fps
mpeg-4
group-concat
evo
textkit
low-level
ctrlp
chaining
moai
libsndfile
fragment-tab-host
dmp
sid
method-overriding
colt
config-files
dbsetup
factors
reserved-words
dynamic-proxy
sanitization
logentries
windows-mobile-6
.net-cf-3.5
asp.net-mvc-scaffolding
threadx
mailcore
fortran77
css-tables
plone-funnelweb
mpmovieplayer
redirectstandardoutput
cross-domain-policy
newsstand-kit
search-path
pureftpd
recordset
opcodes

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App