My problem is computing an array and return a nested object array of to numbers inside using vuejs/javascript? I’m doing it via compute prop with vue js 2.
The array i’m initialy looping looks like this:
[
{
"name": "Bob",
"Points": [{"Lat": 2, "Lon": 3}, {"Lat": 4, "Lon": 5} ]}
},
{
"name": "John",
"Points": [{"Lat": 6, "Lon": 7}, {"Lat": 8, "Lon": 9} ]}
}
]
So Im trying to return smth like [{2, 3}, {4, 5}, {6, 7}, {8, 9}]
I’m trying to make it like this but it fails:
computed: {
departureStops() {
return this.stops.forEach((s) =>
s["points"].forEach((dp) => {
dp.Lat;
console.log("dp.Lat", dp.Lat);
})
);
},
},
I’m expecting to return a nested object array of to numbers inside like
[[1,2], [3,4], [5,6],[7,8]]
2
Answers
You want this:
Or:
For instance:
You don’t return a value in
computed
function, because you useforEach
. If you use like:The result will be: