convert Object to array (javascript)

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

Upvotes: 0

Views: 178

Answers (3)

Nguyen Le Vu Long
Nguyen Le Vu Long

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

funcoding
funcoding

Reputation: 791

var newarr = obj.map((elem) => { return elem.value });

Upvotes: 3

grzesiekgs
grzesiekgs

Reputation: 463

const newArr = oldArr.map((item) => item.value)

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

Upvotes: 2

Related Questions