R
R
Ruslan Dzh2019-02-26 11:26:04
JavaScript
Ruslan Dzh, 2019-02-26 11:26:04

How to convert an object to an array in JS?

There is an object of the following form (the number of values ​​may vary):

{0: {…}, 1: {…}, 2: {…}}
0: {0: "01.01.2019", 1: 11111.01}
1: {0: "02.01.2019", 1: 22222.02}
2: {0: "03.01.2019", 1: 33333.03}
__proto__: Object

You need to convert it to an array so that it looks like this:
[
["01.01.2019",  11111.01],
["02.01.2019",  22222.02],
["03.01.2019",  33333.03],
]

already tried everything using (json.parse, map)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Pavel Kornilov, 2019-02-26
@rdzh

Object.values({
  0: {0: "01.01.2019", 1: 11111.01},
  1: {0: "02.01.2019", 1: 22222.02},
  2: {0: "03.01.2019", 1: 33333.03}
}).map(i => Object.values(i) )

D
Dmitry Komchev, 2019-12-01
@Lebezniy

Object to Array JS

S
Sood21, 2020-07-28
@Sood21

let arr = Array.from(object)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question