I am facing a challenge with an object that has keys containing an index after the underscore. I need to gather each pair of keys with the same index together in order to achieve my expected object. Can someone help me figure out how to accomplish this using either Underscore.js or plain JavaScript?
var obj = {
phoneNumber_0 : "2",
phoneNumber_1 : "0",
phoneType_0 : "Home",
phoneType_1 : "Work"
}
var expected = [
{number: '2', type: 'home'},
{number: '0', type: 'work'},
]