0

I have selected two values from dropdown. I did a console.log and i can see the below results

>[Object,Object]
after expanding above output

>0: Object
   id:"USA"
  >__proto__:Object (all unnecessary information here)
>1: Object
   id:"Russia"
  >__proto__:Object (again all unnecessary information)
  length:2
>__proto__:Array[0]

As you can see, there are 2 objects shown at the output when i select 2 options from dropdown. The id is the value which was selected at dropdown.

I want to only get this Id values from the entire array of objects and get it in a single array. how can i go through this output and get the desired results ?

It is with reference to this multiselect dropdown http://dotansimha.github.io/angularjs-dropdown-multiselect/#/

1 Answer 1

2

Do this

var obj_array = [obj1, obj2, obj3];
var simple_array = obj_array.map(function(obj){
     return obj.id; // or whatever property you want
});
Sign up to request clarification or add additional context in comments.

2 Comments

Array.map is definitely the right solution.
Thanks for voting... :D

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.