node-convert-array-to-csv icon indicating copy to clipboard operation
node-convert-array-to-csv copied to clipboard

Non sorted objects produce wrong result

Open cbou opened this issue 4 years ago • 2 comments

If keys your objects are not sorted the same way the output will be wrong e.g. I switched handle and last from the last object.

const dataObjects = [
  {
    number: 1,
    first: 'Mark',
    last: 'Otto',
    handle: '@mdo',
  },
  {
    number: 2,
    first: 'Jacob',
    last: 'Thornton',
    handle: '@fat',
  },
  {
    number: 3,
    first: 'Larry',
    handle: '@twitter',
    last: 'the Bird',
  },

It outputs:

number,first,last,handle
1,Mark,Otto,@mdo
2,Jacob,Thornton,@fat
3,Larry,@twitter,the Bird

But it should be

number,first,last,handle
1,Mark,Otto,@mdo
2,Jacob,Thornton,@fat
3,Larry,the Bird,@twitter

cbou avatar Feb 06 '21 07:02 cbou

I'll take a look at it asap.

Contributions are welcome 👍

aichbauer avatar Feb 06 '21 11:02 aichbauer

wake up bro

ghost avatar Nov 20 '22 11:11 ghost