Is there a more efficient way to define this object?
const list = {
1: {
Name: 'Fanshaws Room',
Lat: 51.754350,
Long: -0.087278
},
2: {
Name: 'Old phone box Brickendon Lane',
Lat: 51.755153,
Long: -0.083999
},
3: {
Name: 'Clementsbury',
Lat: 51.771667,
Long: -0.080833
},
4: {
Name: 'Blackfields Farm',
Lat: 51.7720,
Long: -0.06475
}
};
Is there a particular reason you need to define the outer layer as an object, and not just an array-of-objects?
1 Like
No, none at all. I get my proverbials in a twist with multi-dimensional “things”.
const list = [{ Name: 'Fanshaws Room', Lat: 51.754350, Long: -0.087278},
{ Name: 'Old phone box Brickendon Lane', Lat: 51.755153, Long: -0.083999},
{ Name: 'Clementsbury', Lat: 51.771667, Long: -0.080833 },
{ Name: 'Blackfields Farm', Lat: 51.7720, Long: -0.06475}];
(or if you need the indexes to be 1,2,3,4…)
const list = [{},
{ Name: 'Fanshaws Room', Lat: 51.754350, Long: -0.087278},
{ Name: 'Old phone box Brickendon Lane', Lat: 51.755153, Long: -0.083999},
{ Name: 'Clementsbury', Lat: 51.771667, Long: -0.080833 },
{ Name: 'Blackfields Farm', Lat: 51.7720, Long: -0.06475}];
3 Likes
Cool, thanks. Yes, I need the initial index as 1, 2, 3 etc as I’m using a for loop to extract the data - although I guess I could change that too…
Edit: Oh, I see what you mean! Der!
1 Like
For loops normally can start with 0 either
I know. I missed the point. Starting at zero is probably better.
2 Likes
system
Closed
8
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.