I have an array of objects like this :
var kvArray = [
{
number: '123',
duration: '00:00:00'
},
{
number: '324',
duration: '00:00:00'
}]
I want to generate a new array from the above array such that the number key becomes the index.
This is what I tried
var kvArray = [
{
number: '123',
duration: '00:00:00'
},
{
number: '324',
duration: '00:00:00'
}]
var reformattedArray = kvArray.map(obj =>{
var rObj = {};
rObj[obj.number] = obj.duration;
return rObj;
});
console.log(reformattedArray)
The above output looks like this in the console with 0 and 1 as the index:

Instead I want the output array to be like this :
123: {"00:00:00"}
324: {"00:00:00"}
such that instead of 0 , 1 as the index I have 123 and 324 as the index. So that if write test_array[123] in my code I should be able to get 00:00:00 in the output. Is it possible to achieve what I'm trying to do here? Suggest better ways how this can be done
How do I do this?