Merging javascript objects into an array

I have a table of objects like this

let coordinates = [
        {
          x: 0.579685,
          y: 0.566285
        },
        {
          x: 1.580644,
          y: 0.653808
        },
        {
          x: 5.549772,
          y: 5.804705
        },
        {
          x: 0.54706,
          y: 4.536875
        },
        {
          x: 5.539847,
          y: 3.547974
        }
      ];

I want to merge it like this

let newCoordinates = [
        [
          {
            x: 0.579685,
          	y: 0.566285
          },
          {
            x: 1.580644,
          	y: 0.653808
          }
        ],
        [
          {
            x: 5.549772,
          	y: 5.804705
          },
          {
            x: 0.54706,
          	y: 4.536875
          }
        ],
        [
          {
            x: 5.539847,
          	y: 3.547974
          }
        ]
      ];

Is there an easy way to do this?

What have you tried so far? This should be doable.

I wouldn’t call that “merging”, I’d call that “chunking”. You might check out this FCC challenge, that’s basically what it is doing.

3 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.