myArray = ['1', '2', '3'];
myObj = { 1-vehicle : 'car', 2-vehicle : 'bike', 3-vehicle : 'train' };
resultObj = {
'1': { '1-vehicle': 'car' },
'2': { '2-vehicle': 'bike' },
'3': { '3-vehicle': 'train' }
};
I am having an object where each key is starting with a number and also I have and array with some values. I am trying to match those key and values and split up the object. Please help me. Thanks in advance.
I have tried it and i am posting my code below but I am not successful
{
Object.keys(myObj).filter((key: any) => {
for (const i in myArray) {
if (myArray[i] === key.charAt(0)) {
newObj[key] = myObj[key]
resultObj[myArray[i]] = newObj
}
}
})
}
id.