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

Could not cast value of type 'Swift.Array<Swift.AnyObject>' to 'Swift.Array<SomeModelClass>'
string array to new sheet
Sum, Median and Mean of rainfall over different periods in Excel
How to put array of string into another array in Swift?
Finding the k'th element in unsorted array using external function
How to stack arrays in repa (Haskell)
Comma delimited string to array using regular expressions
Can somebody please explain this pseudo code to me in terms of java code?
Parsing currency value in Excel VBA
Replacing values in one array/list by index of another array/list
Iterate over an array in a certain order, so that it is sampled fairly
Perl - initialization of hash
Array as property in BreezeJS model
Swift - check if array contains element with property [duplicate]
Ruby Array of Arrays Group and Count by Values
How to parse XML and Store in array in Mac OS using VBA?

Categories

HOME
sas
plsql
crate
jar
wmic
performancecounter
laravel-5.3
vs-team-services
cocos2d-x-3.0
ruby-on-rails-3
jrebel
rebol
bro
httpclient
dropbox
ipfs
cortex-a
gatsby
simple-injector
scaling
mule-studio
rhapsody
jsonserializer
uiautomator
tampermonkey
hanami
lync-2013
frp
multichoiceitems
mangodb
encase
superpowered
nunit-3.0
rider
boilerplate
agent
twiki
constants
html-agility-pack
automator
drawingarea
gist
persistent
spring-data-hadoop
workflow-foundation-4.5
tofixed
visual-studio-templates
bettercms
autoresize
garrys-mod
onresume
pspice
master
gradle-script-kotlin
windows-azure-pack
xib
audioqueue
children
json-schema-validator
spoofing
uwp-maps
date-format
spinlock
post-processing
handlebars.java
hateoas
fabric-twitter
textkit
subresource-integrity
pyrocms
achartengine
on-duplicate-key
xjc
twitter-rest-api
uos
web-component-tester
guzzle6
jython-2.7
android-search
lexicographic
gmaps4rails
kendo-mvvm
collabnet
ssms-addin
delphi-xe3
opensocial
broadcasting
sanitization
sim900
soa-suite
qss
mozart-mvc
sequelpro
mvccontrib
maven-ear-plugin
z-machine
cross-domain-policy
rubycas
sendfile
requestfactory
osx-leopard
google-instant
pci-bus
front-controller
savestate
system-codedom-compiler
data-entry

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