“Konversi array ke objek” Kode Jawaban

Objek JavaScript ToArray

var obj = {"1":5,"2":7,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0}
var result = Object.keys(obj).map(function(key) {
  return [Number(key), obj[key]];
});

console.log(result);
Handsome Hare

JS array menjadi objek

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

// convert array to th object
const obj = Object.assign({}, names);

// print object
console.log(obj);

// {0: "Alex", 1: "Bob", 2: "Johny", 3: "Atta"}
Plain Pygmy

JS array untuk keberatan dengan kunci

const arr = ['a','b','c'];
const res = arr.reduce((a,b)=> (a[b]='',a),{});
console.log(res)
Sleepy Squirrel

Konversi array ke objek dalam 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);
Naughty Nightingale

Konversi objek menjadi array javascript

var object = {'Apple':1,'Banana':8,'Pineapple':null};
//convert object keys to array
var k = Object.keys(object);
//convert object values to array
var v = Object.values(object);
Dr. Hippo

Konversi array ke objek

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

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

Jawaban yang mirip dengan “Konversi array ke objek”

Pertanyaan yang mirip dengan “Konversi array ke objek”

Lebih banyak jawaban terkait untuk “Konversi array ke objek” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya