“Object.keys Map” Kode Jawaban

Array peta javascript objek mendapatkan kunci

var foo = {
  'alpha': 'puffin',
  'beta': 'beagle'
};

var keys = Object.keys(foo);
console.log(keys) // ['alpha', 'beta'] 
// (or maybe some other order, keys are unordered).
Smoggy Shark

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

JavaScript mendapatkan semua kunci objek

myObject = {
	"key": "value",
    "key2":"value2"
}
Object.keys(myObject);
//console.log(Object.keys(myObject))   = ["key", "key2"]
Batman

Kunci Objek JavaScript

const object1 = {
  a: 'somestring',
  b: 42,
  c: false
};

console.log(Object.keys(object1));
// expected output: Array ["a", "b", "c"]
Kaotik

JavaScript Peta Kunci Objek

const object = {1: 'a', 2: 'b', 3: 'c'};

// convert to the array keys 
let array =Object.keys(object);

// index is based on zero
let newArray = array.map((item, index) => {
    console.log(`Item => "${item}", Index => ${index}`);
    return item * 2;
});

// newArray will be [2, 4, 6]
Poor Platypus

Object.keys Map

const object = {'a': 1,'b': 2, 'c': 3};

// convert to the array keys 
let array = Object.keys(object);

console.log(array);
// => ['a', 'b', 'c']

let newArray = array.map(item => return item + '-X' )

console.log(newArray);
// => ['a-X', 'b-X', 'c-X']
Poor Platypus

Jawaban yang mirip dengan “Object.keys Map”

Pertanyaan yang mirip dengan “Object.keys Map”

Lebih banyak jawaban terkait untuk “Object.keys Map” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya