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 me
CodePudding user response:
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
CodePudding user response:
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']];