I have the below arrays:
const elements = ['12345', '12346', '12347', '12348', '12349', '12350'];const fruits = ['Apple', 'Ball'];
I am trying to generate a Map, with array: elements
as key, based on the length of array: fruits
. And wanted to discard other elements.
So, it should be like:
eleFruitMap: { '12345' => 'Apple','12346' => 'Ball'}
But, with my implementation, I am getting as:
eleFruitMap: { '12347' => 'Apple','12348' => 'Ball','12349' => undefined,'12350' => undefined,}
I have tried:
const elements = ['12345', '12346', '12347', '12348', '12349', '12350'];const fruits = ['Apple', 'Ball'];let eleFruitMap = elements.slice(fruits.length).map((key, index) => ({ [key]: fruits[index]}));console.log('NEW MAP: ', eleFruitMap);
But, all it is doing is - just removing the first element ('12345') from the array: elements and making second element ('12346') as the first key and still keeping 'undefined' values.
How can I achieve my goal?