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

data structure interview : find max number in array
codeigniter pass array in session and retrieve
Make a replaceAll look once at each char from String (because of for-loop)
array of class keep throwing error messages
accumarray(subs, val) where val has zeros
bash curl array from text file [closed]
Quickest way to hide an array of pictureboxes
Perl IO::Pipe does not work within arrays
Array Declaration in CFScript
Select combination of elements from array whose sum is smallest possible positive number
Issue While Loop Apache Status
Add multiple polylines to a single Array
variable changing value unexpectedly only when equal to zero in MASM32
An issue with Arrays
Converting String to array of characters
MATLAB: get index of minima in 3D array

Categories

HOME
signalr
winapi
wsdl
uibutton
label
google-sheets-api
transparent
checksum
algorithmic-trading
histogrammar
tumblr
bro
google-spreadsheet-api
gimp
height
powershell-v3.0
sendkeys
scala-native
medium-editor
python-unicode
android-toolbar
factor-analysis
tree-traversal
primes
ejbca
kadanes-algorithm
ip-camera
cocoa-touch
python-textprocessing
switching
spring-data-neo4j
roundcube
gettext
service-locator
google-guava-cache
wfp
fax
agent
restful-url
spring-bean
lftp
python-idle
onmouseover
rapidweaver
chrome-remote-desktop
jexl
quintus
hpcc
jszip
laravel-query-builder
garrys-mod
coremidi
master
alter
tomee
chessboard.js
tomcat5
radians
boost-hana
logcat
spinlock
asp.net-mvc-partialview
sonarqube5.3
data-import
document-oriented-db
site-prism
rad
sem
twython
ffserver
shift-jis
scrollspy
consensus
android-search
tilestache
sysctl
left-recursion
line-numbers
adcolony
node-imagemagick
eclipse-classpath
planetary.js
config-files
winrt-httpclient
backbone-relational
adomd.net
objcmongodb
transitive-closure-table
cgpath
android-4.0
crocodoc
mvccontrib
css-tables
moq-3
cadisplaylink
entity-framework-ctp5
datacontract
associative
sendfile
kpi
winsnmp
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