Reputation: 818
Have object look like this:
Need to creacte something like this
var newarr = [1,2]
In array must be added just only VALUE from object
Upvotes: 0
Views: 178
Reputation: 71
Mapping an Array to another array is a fairly frivolous task in JavaScript
var newarr = oldarr.map(function(element) { return element.value });
Using ES6's array function syntax:
var newarr = oldarr.map(element => element.value);
You can also use the classic loop
var newarr = [];
for(var i = 0; i < oldarr.length; i++) newarr.push(oldarr[i].value)
Upvotes: 0
Reputation: 463
const newArr = oldArr.map((item) => item.value)
Map each item of oldArr and return value property of that item.
Upvotes: 2