AngularJS - Factory to hold an Array

How can I update this code to  hold an array of   values.

I want to hold FIELDNAME  and the VALUE

I want to set / add to the list by doing the following - add a value to the array/list.
       

   userFilters.setData(' lastname', 'smith');
   userFilters.setData(' firstname', 'bob');
   userFilters.setData(' Mi', 'D');

And have the object hold an Array of

'lastname','smith'
'firstname','bob'
'mi','D'





App.factory('userFilters', [function () {

    var data = {};

    var getData = function (field) {
        return data[field];
    };

    var setData = function (field, value) {
        data[field] = value;
    };

    return {
        getData: getData,
        setData: setData
    }
}]);
LVL 1
JElsterAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alexandre SimõesManager / Technology SpecialistCommented:
Still I think this is not the right approach.
How are you planning to get that data? You still need an ID right?

userFilters.setData(1, { lastname: 'smith', firstname: 'bob', mi: 'D' });
userFilters.setData(2, { lastname: 'doe', firstname: 'john', mi: 'E' });

Open in new window


To get the last name of the user 2, you'll do:
userFilters.getData(2).lastname;

Open in new window

0
JElsterAuthor Commented:
I just want to set the values and loop through the array

I want to set like this

   userFilters.setData(' lastname', 'smith');
   userFilters.setData(' firstname', 'bob');
   userFilters.setData(' Mi', 'D');
0
Alexandre SimõesManager / Technology SpecialistCommented:
Can you give me an example of how you want to use the loop?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JElsterAuthor Commented:
See my next question.. thx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.