0

Have object look like this:

enter image description here

Need to creacte something like this

var newarr = [1,2]

In array must be added just only VALUE from object

4
  • 2
    again, please add the object in text form. Commented Mar 13, 2017 at 12:36
  • Array.prototype.map()
    – Andreas
    Commented Mar 13, 2017 at 12:38
  • You're trying to convert an array of object to an array? Commented Mar 13, 2017 at 12:38
  • var yourArray=yourObject.map(function(item){return item.value}); Commented Mar 13, 2017 at 12:38

3 Answers 3

3
var newarr = obj.map((elem) => { return elem.value });
0
2
const newArr = oldArr.map((item) => item.value)

Map each item of oldArr and return value property of that item.

0

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)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.