Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

convert array to object in javascript

const array =    [ [ 'cardType', 'iDEBIT' ],
      [ 'txnAmount', '17.64' ],
      [ 'txnId', '20181' ],
      [ 'txnType', 'Purchase' ],
      [ 'txnDate', '2015/08/13 21:50:04' ],
      [ 'respCode', '0' ],
      [ 'isoCode', '0' ],
      [ 'authCode', '' ],
      [ 'acquirerInvoice', '0' ],
      [ 'message', '' ],
      [ 'isComplete', 'true' ],
      [ 'isTimeout', 'false' ] ];
      
const obj = Object.fromEntries(array);
console.log(obj);
Comment

javascript convert array to object

function arrayToObject(arr) {
    var obj = {};
    for (var i = 0; i < arr.length; ++i){
        obj[i] = arr[i];
    }
    return obj;
}
var colors=["red","blue","green"];
var colorsObj=arrayToObject(colors);//{0: "red", 1: "blue", 2: "green"}
Comment

javascript convert array to object

// Also, the following works well:
// IF the array came as follows (you cannot declare an array like that)
const obj = Object.assign({}, ['name': 'Alex', 'age': 43, 'gender': 'male']);
console.log(obj);
Comment

convert array to object

const names = ['Alex', 'Bob', 'Johny', 'Atta'];

const obj = Object.assign({}, names);
console.log(obj);
Comment

es6 convert array to object

const result = arr.reduce((obj, cur) => ({...obj, [cur.sid]: cur}), {})
Comment

js convert array to object

const names = ['Alex', 'Bob', 'Johny', 'Atta'];

const obj = Object.assign({}, names);
Comment

js array to object

const result = arr.reduce((obj, cur) => ({...obj, [cur.sid]: cur}), {})
Comment

PREVIOUS NEXT
Code Example
Javascript :: node js connect to mongodb using mongoose 
Javascript :: js object clear 
Javascript :: how to make a popup in javascript -html 
Javascript :: disable button using jquery 
Javascript :: axios cnd 
Javascript :: js get json object keys 
Javascript :: redux dispatch no connect 
Javascript :: fat arrow function 
Javascript :: using / for division is deprecated and will be removed in dart sass 2.0.0 
Javascript :: base64 encoded data to object in javascript 
Javascript :: substr() javascript 
Javascript :: react context 
Javascript :: how to stop re rendering in react 
Javascript :: Auto open browser when run dev nextjs 
Javascript :: textarea javascript set value 
Javascript :: link in directive angularjs 
Javascript :: date in react js 
Javascript :: editor js to html 
Javascript :: mongodb limit find node 
Javascript :: javascript replaceall 
Javascript :: how get height elemnt with that margin in js 
Javascript :: loop queryselector 
Javascript :: apply css to iframe content javascript 
Javascript :: convert int to timestanp js 
Javascript :: url query example 
Javascript :: angular go to external url with blank target 
Javascript :: removeeventlistener click 
Javascript :: javascript return multiple values from a function 
Javascript :: parse json to dart model 
Javascript :: check for string anagram javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =