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

How to make array values all capital letters lazarus
How do I separate unique and duplicate items from two arrays in perl?
My randomized Array list is not working
Sorting variable-length items / Algorithms
MongoDB : Single update on multiple fields V/S Multiple updates on single field?
Maximum difference between two elements is equal to solve Maximum Subarray?
Create an array from a CSV list
Finding the contents of an Array 'a' after the loop completes
How to replace a single character in a string?
perl find lines containing string 1 then extract character between string 2 and 3
ElasticSearch - why ScriptDocValues returns unique values?
How to loop through output of a command?
Combining multiple arrays into one, indexing sequentially
Printing an array of integers in a collection of buttons, Swift
Passing complex arrays into a function, getting incorrect answer back
How can I create a foreach with a key that has a space in the name?

Categories

HOME
ipython
decorator
computer-vision
angular2-directives
checksum
snap.svg
iis-7.5
file-io
google-classroom
packer
getorgchart
wicket
ndis
qt-installer
uicollectionview
redux-observable
grub2
thumbnails
jive
piwik
tflearn
osmdroid
maximo
owl-api
winscp
fileinfo
thinking-sphinx
aurelia-binding
devforce
svnkit
npm-shrinkwrap
large-data
jquery-cycle2
lego
mms
npm-publish
xamarin.uitest
strstr
ntfs-mft
pdftk
ttcn
onmouseover
vcf
broadcast
maintenance
slot
slidesjs
static-code-analysis
collapsingtoolbarlayout
lotus
gulp-typescript
atlassian-crowd
galleriffic
unsatisfiedlinkerror
gradle-eclipse
kendo-combobox
project-online
django-south
windowlistener
programming-paradigms
base32
ffserver
pgm
isml
adobe-indesign
guzzle6
consensus
magento-1.12
sqoop2
multipleselection
pisa
belongs-to
viewflipper
node-imagemagick
bsp
korma
gfs
logentries
document-database
fogbugz-api
goinstant
swrl
pep8
zend-lucene
android-contextmenu
icsharpcode
tridion2009
n-layer
unions
gdt
objective-c-protocol
ubuntu-11.04
datacontract
executable-format
windows-live-id
chatroom
camtasia
communicationexception
multibyte-functions
inline-if
virtualquery
handheld

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