Agata
Agata

Reputation: 362

get object response value

I got a response from the backend the response is an object how can I get the arrays from the object I tried to use Object entries but I can't get the arrays can you please help meenter image description here

Upvotes: 0

Views: 242

Answers (2)

Maxime Chevallier
Maxime Chevallier

Reputation: 307

You are looking for the Object.values to retrieve just the value part of your object.

Example:

const object = {
  "20-01-22": ['a', 'b', 'c'],
  "21-01-22": ['b', 'c'],
  "22-01-22": ['d', 'f']
};

const arrays = Object.values(object)

// => [['a', 'b', 'c'], ['b', 'c'], ['d', 'f']];

Upvotes: 1

Matteo
Matteo

Reputation: 147

You can use a for:

Example:

const cars = ["BMW", "Volvo", "Saab", "Ford", "Fiat", "Audi"];

let text = "";
for (let i = 0; i < cars.length; i++) {
  text += cars[i] + "<br>";
}

document.getElementById("demo").innerHTML = text;

Source: https://www.w3schools.com/js/tryit.asp?filename=tryjs_loop_for

Upvotes: 1

Related Questions