“peta javascript ke objek” Kode Jawaban

Peta melalui kunci javascript

var myObject = { 'a': 1, 'b': 2, 'c': 3 };

Object.keys(myObject).map(function(key, index) {
  myObject[key] *= 2;
});

console.log(myObject);
// => { 'a': 2, 'b': 4, 'c': 6 }
Bad Bat

objek untuk memetakan javascript

const map = new Map(Object.entries({foo: 'bar'}));

map.get('foo'); // 'bar'
Dark Dotterel

peta javascript ke objek

Object.fromEntries(Map)
David Diamant

inisialisasi peta js

let map = new Map()
map['bla'] = 'blaa'
map['bla2'] = 'blaaa2'

console.log(map)  // Map { bla: 'blaa', bla2: 'blaaa2' }
PSK1103

peta ke objek

let map = new Map();
map.set("a", 1);
map.set("b", 2);
map.set("c", 3);

let obj = Array.from(map).reduce((obj, [key, value]) => (
  Object.assign(obj, { [key]: value }) // Be careful! Maps can have non-String keys; object literals can't.
), {});

console.log(obj); // => { a: 1, b: 2, c: 3 }
Anxious Alpaca

mengembalikan objek dari peta javascript

const rockets = [
    { country:'Russia', launches:32 },
    { country:'US', launches:23 },
    { country:'China', launches:16 },
    { country:'Europe(ESA)', launches:7 },
    { country:'India', launches:4 },
    { country:'Japan', launches:3 }
];

const launchOptimistic = rockets.map(elem => (
  {
    country: elem.country,
    launches: elem.launches+10
  } 
));

console.log(launchOptimistic);
 Run code snippet
code fighter

Jawaban yang mirip dengan “peta javascript ke objek”

Pertanyaan yang mirip dengan “peta javascript ke objek”

Lebih banyak jawaban terkait untuk “peta javascript ke objek” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya