Oreol Noumodong

Oreol Noumodong


Convert an array of strings of size two to an object in JavaScript

11 Aug, 2022 - 03:49 AM

Let's say we have an array of strings of size two in which we want one to be the key and the other the value. Our job is to form an object from this array.
Here is the sample array:
let arr = ["token", "eyJfcmFpbHMiOnsibWVzc2FnZSI6IlcxczBPRG"]
We want to turn into this:
const obj = {
The full code will be:
let obj = {}; 
const arr = ["token", "eyJfcmFpbHMiOnsibWVzc2FnZSI6IlcxczBPRG"];
obj[arr[0]] = arr[1];


Let's work together!

Available for remote opportunities, collaboration, or mentorship.

Build with Next.js, Tailwindcss, Express.js and Vercel