I have a JSON array object as follows:
var orders = [{
orderId: 1,
firstName: 'John',
lastName: 'Smith',
address: {
street: '123 Main Street',
city: 'New York',
zip: 10001
}
}, {
orderId: 2,
firstName: 'John',
lastName: 'Smith',
address: {
street: '456 Main Street',
city: 'New York',
zip: 10001
}
}, {
orderId: 3,
firstName: 'John',
lastName: 'Smith',
address: {
street: '123 Main Street',
city: 'New York',
zip: 10001
}
}, {
orderId: 4,
firstName: 'John',
lastName: 'Smith',
address: {
street: '123 Main Street',
city: 'New York',
zip: 10002
}
}];
I am trying to use underscore.jsto create a new array object, grouped by address, to match the use case of all orders sent to 123 Main Street, New York, 1001.
Is this the underscore.jsright approach to this? If so, how do I do this? Any hints would be helpful.
source
share