Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

convert 2 dimensional array to js object

function arr2obj(arr) {
  
    // Create an empty object
    let obj = {};
  
    arr.forEach((v) => {
  
        // Extract the key and the value
        let key = v[0];
        let value = v[1];
  
        // Add the key and value to
        // the object
        obj[key] = value;
    });
  
    // Return the object
    return obj;
}
  
console.log(
    arr2obj([
        ["John", 12],
        ["Jack", 13],
        ["Matt", 14],
        ["Maxx", 15],
    ])
);
Comment

PREVIOUS NEXT
Code Example
Javascript :: canvas font colour 
Javascript :: javascript hwo to return largest value with index 
Javascript :: js fake promise with timeout 
Javascript :: angular create project in current directory 
Javascript :: jquery scroll into view 
Javascript :: separate digits in javascript 
Javascript :: unique string generator javascript 
Javascript :: choose jsp 
Javascript :: array contains case insensitive javascript 
Javascript :: cdnjs smeantic ui 
Javascript :: javascript regular expression for alphanumeric 
Javascript :: javascript generate random string 
Javascript :: js canvas draw polygon 
Javascript :: jstl replace 
Javascript :: nodejs sharp get image size 
Javascript :: regex find lines containing two strings 
Javascript :: how to add multiple css style in javascript 
Javascript :: discord javascript error cannot find module 
Javascript :: add event listener on modal close 
Javascript :: writing to file in node js 
Javascript :: react native open email client 
Javascript :: random generating api for quotes 
Javascript :: get buffer from jimp js 
Javascript :: Find channel discord js 
Javascript :: javascript clear text in textarea 
Javascript :: javascript button go to url 
Javascript :: js document.getelementsbyclassname modify innertext 
Javascript :: sqlite3 multithreading nodejs 
Javascript :: detect keypress 
Javascript :: angular get current time 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =