Результат loda sh groupBy()
дает { "student": [], "undefined": [] }
.
const splittedData = _.groupBy(datas, 'type');
Можно ли дать имя для ключа undefined
?
const datas = [
{
_id: "5ea2ecbde53c090b4ba4fa12",
firstName: "Dillon",
surname: "Mclaughlin",
guid: "a727438f-4ddc-4422-af4a-c7396fda73c3",
isActive: true,
balance: "$3,331.33",
picture: "http://placehold.it/32x32",
age: 37,
type: "student"
},
{
_id: "5ea2ecbd067a8ad1cb1f9e62",
firstName: "Fleming",
surname: "Austin",
guid: "e228bbea-ef6b-4709-995c-bf485fa3665c",
isActive: true,
balance: "$1,869.92",
picture: "http://placehold.it/32x32",
age: 35
},
{
_id: "5ea2ecbd0d1a074b255a1349",
firstName: "Kaufman",
surname: "Alford",
guid: "176fb7fe-b7bc-4574-8887-4252a042b24a",
isActive: true,
balance: "$2,163.34",
picture: "http://placehold.it/32x32",
age: 29,
type: "student"
},
{
_id: "5ea2ecbd1162ee44119aa0d3",
firstName: "Sykes",
surname: "Petty",
guid: "92b13963-7d32-469c-be80-c88728a7842a",
isActive: false,
balance: "$2,728.46",
picture: "http://placehold.it/32x32",
age: 37
},
{
_id: "5ea2ecbd297854a2f85909a4",
firstName: "Stuart",
surname: "Pickett",
guid: "322031f9-1a71-44ae-b1cf-cbe7430b78b6",
isActive: false,
balance: "$1,725.25",
picture: "http://placehold.it/32x32",
age: 25,
type: "student"
},
{
_id: "5ea2ecbd6ef4a9bee37a223a",
firstName: "Berg",
surname: "Hewitt",
guid: "ab05bed9-29e4-4570-aa12-fead954417b0",
isActive: false,
balance: "$2,935.72",
picture: "http://placehold.it/32x32",
age: 31
}
];
const splittedData = _.groupBy(datas, 'type');
console.log(splittedData);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.min.js"></script>
Демонстрация: https://codepen.io/athimannil/pen/pojePYK