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 :: scrollheight jquery 
Javascript :: how to divide equal 3 parts of an array javascript 
Javascript :: get number from range line js 
Javascript :: sql json_extract 
Javascript :: convert timestamp to date javascript 
Javascript :: loop through map in js 
Javascript :: resize image react native 
Javascript :: async await catch error 
Javascript :: datatable cdn 
Javascript :: js get data from form 
Javascript :: jquery trigger event when scroll to div 
Javascript :: convert milliseconds to minutes and seconds javascript 
Javascript :: return random rows sqlite 
Javascript :: how to change the tab text in React 
Javascript :: js canvas rectangel 
Javascript :: ajax get form data 
Javascript :: date.tolocaledatestring is not a function 
Javascript :: curl post json file 
Javascript :: white screen issue in react native splashscreen 
Javascript :: jQuery CSS Classes 
Javascript :: copyright js 
Javascript :: lottie react 
Javascript :: javascript from method 
Javascript :: object values javascript 
Javascript :: require express 
Javascript :: regex any char except 
Javascript :: find the max length of string elements in an array 
Javascript :: how to get the all input element id value using jquery 
Javascript :: capitalize the string 
Javascript :: js shortcut 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =