You can try with Array.prototype.map()
The
map()
method creates a new array with the results of calling a provided function on every element in the calling array.
And Object.values()
The
Object.values()
method returns an array of a given object’s own enumerable property values.
As you have single value in the object use [0]
to return that.
var ObjArray = [{item1 : 'Foo'}, {item2 : 'Bar'}];
var array = ObjArray.map(i => Object.values(i)[0]);
console.log(array);
Using for...of
and push()
var array = [];
var ObjArray = [{item1 : 'Foo'}, {item2 : 'Bar'}];
for(var i of ObjArray){
array.push(Object.values(i)[0]);
}
console.log(array);
solved Push only values of an object array into another array