Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

How to transform a cluttered contact list into alphabetical-ordered list using reduce [closed]

$
0
0

want to create an array of objects that contains the first alphabet of the people as the key and an array of the names that start with that name.

Example:

  const listContacts = [    {name: 'Ana maria', phone: '5555-5555'},    {name: 'Anthony M. Tabor', phone: '5553-5555'},    {name: 'Lorraine J. Welling', phone: '5553-5585'},    {name: 'Bertha A. Mathis', phone: '5553-5587'},    {name: 'Frankie M. Wilson', phone: '5553-5587'},    {name: 'Steven M. Long', phone: '5553-5587'},    {name: 'Carole T. Cook', phone: '5553-4587'},  ];  // Expected output  const newListContacts = [    {      A: [        {name: 'Ana maria', phone: '5555-5555'},        {name: 'Anthony M. Tabor', phone: '5553-5555'},      ],    },    {      B: [{name: 'Bertha A. Mathis', phone: '5553-5587'}],    },    {      C: [{name: 'Carole T. Cook', phone: '5553-4587'}],    },    {      F: [{name: 'Frankie M. Wilson', phone: '5553-5587'}],    },    {      L: [{name: 'Lorraine J. Welling', phone: '5553-5585'}],    },    {      S: [{name: 'Steven M. Long', phone: '5553-5587'}],    },  ];

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>