Is there a better way

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 :slight_smile:

I know. I missed the point. Starting at zero is probably better.

2 Likes