get the data of an array in angularjs

1

I have the following array :

vm.model= {"left":false,"middle":true,"right":false}

From which I want to obtain the value of each item of the arrangement and save it in the Database , but I do not know how to obtain for example left and its value false in angularjs .

In synthesis I need to get the first position of the arrangement in other languages would be vm.model[0] first position.

I would appreciate an answer

    
asked by user49075 25.06.2017 в 09:09
source

2 answers

1

Really what you are doing is creating an object that is why it does not work with vm.model[0] to access any of the elements it would be with the dot notation of the objects vm.model.left with this you will have access to the first value.

To use an array it would be created with brackets vm.model = [true,false,true] in this way you can access with vm.model[1] but I understand that what you want is to create an associative array for that you should do it like this:

vm.model = new Array();
vm.model['uno'] = 1;
vm.model['dos] = 2;

And you could access as you want vm.model['uno'] or vm.model[0]

But good personally when I want to use the associative arrays I use the object notation that you indicate is the one that I find the most practical but that you will know better than anyone which of the 3 ways is what you need.

    
answered by 25.06.2017 в 13:14
0

What happens to me about this model Model: {"left": true, "middle": true, "right": true} I want to get the following result Results: ["left", "middle", "right"]; is a checkbox-group of angularjs which I'm using to get values from the database but my problem is going to save the values that are in the results. variables used  vm.checkModel = {};  vm.checkResults = [];

I really want you to help me I am new to angularjs and javascritp and I do not understand many on the subject. I would appreciate an answer.

    
answered by 25.06.2017 в 17:08