kennechu kennechu - 1 year ago 104
Javascript Question

Clear a list or dictionary in Angularjs with a key, value structure

A very basic question, I have a list or dictionary in AngularJS with a key,value structure like this:

$scope.itemList = {}

This list fills with data coming from a JSON file, what I need to do is to clear this list at some point but I dont know how to do it,

I tried the following but didnt worked.


Some help would be great.

Note: I said a list but actually is an object what I have because of
the {}, I'll leave the question as is, someone can think in a wrong
way as I did.

Answer Source

First thing is that declaring variable with {} means object not list.

To clear a object you have to re-define it again

$scope.itemList = {}

To declare a list you have to use like this

$scope.itemList = [];

And to clear list

Try like this


or re-declare it again.

$scope.itemList = [];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download