Contact: aviboots(AT)netvision.net.il
39,870 questions
51,793 answers
573 users
const arr = ['nodejs', 'c', 'c++']; const obj = Object.assign({}, arr); console.log(obj); /* run: { '0': 'nodejs', '1': 'c', '2': 'c++' } */
const arr = ['nodejs', 'c', 'c++']; const obj = {...arr}; console.log(obj); /* run: { '0': 'nodejs', '1': 'c', '2': 'c++' } */
const arr = ['nodejs', 'c', 'c++']; const obj = {}; arr.forEach((element, index) => { obj['key_' + index] = element; }); console.log(obj); /* run: { key_0: 'nodejs', key_1: 'c', key_2: 'c++' } */