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

Return Array from Function in Swift
Bash: Make the code dynamic by array using curl
Swift: How can I check to see if an object is in an array?
Whats's the proper way to loop through an array for an api in laravel 5.1
How to create an array of SCNNode in swift
How to reject arrays with unwanted number range
Ruby Array Errors. Input won't enter array issue
Writing an Int-Array to a text file
What is the best way to save/load contents of array to file?
D: Creating an array of templated objects
cURL post json data, json array and image files REST api testing
Tcl array sorting based on values
How do I get all the values from a hash that are in an array?
Get an array dynamicaly from a factory
How to split a string by new lines in Swift
VB.net how to serialize list / array of json objects

Categories

HOME
python
laravel-5
dotnetrdf
shopify
dynamics-crm
sed
google-sheets-api
is-empty
adsense
dropbear
ctypes
local
maxima
jcl
tree-traversal
tortoisegit
flexboxgrid
sql-update
thingsboard
hhvm
facebook4j
jquery-waypoints
npm-install
searchbar
tfs2013
jflex
scalajs-react
tampermonkey
forum
vertex-buffer
autofill
encase
outsystems
hawtio
pycparser
infusionsoft
soundjs
intellilock
intellij-idea-2016
intersystems-ensemble
crop
rdw
vcf
tuleap
production-environment
jags
web-deployment-project
pinvoke
tiddlywiki
xmgrace
spell-checking
greenhills
slidesjs
lotus
pspice
android-navigationview
firepath
pagekit
string-parsing
gmsmapview
elastix
inet
mfc-feature-pack
git-rebase
void
anythingslider
python-winshell
urn
manjaro
digits
pl-i
libssh2
smartystreets
level
winrt-httpclient
visual-studio-addins
gamepad
magicalrecord-2.2
nservicebus4
dynamic-binding
backbone-relational
client-side-scripting
shortcuts
reporting-tools
htmltextwriter
tridion2009
blockingqueue
cross-domain-policy
shared-objects
curljs
dcpu-16
.app
symbol-server
exitstatus
hadoop-plugins
graniteds
grooveshark
swfloader
hmacsha1
dotproject





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