“Entri objek JS” Kode Jawaban

iterate Object JavaScript

let obj = {
	key1: "value1",
	key2: "value2",
	key3: "value3",
	key4: "value4",
}
Object.entries(obj).forEach(([key, value]) => {
	console.log(key, value);
});
Excited Elk

JavaScript iterate Nilai kunci objek

Object.entries(obj).forEach(([key, value]) => {
	console.log(key, value);
});
Jealous Jay

untuk nilai kunci dalam javascript objek

for (const [key, value] of Object.entries(object1)) {
  console.log(`${key}: ${value}`);
}
Smoggy Shark

Entri objek JavaScript

// Object Entries returns object as Array of [key,value] Array
const object1 = {
  a: 'somestring',
  b: 42
}
Object.entries(object1) // Array(2) [["a", "something"], ["b", 42]]
  .forEach(([key, value]) => console.log(`${key}: ${value}`))
// "a: somestring"
// "b: 42"
POG

Entri objek JS

var obj = { foo: 'bar', baz: 42 };
console.log(Object.entries(obj)); // [ ['foo', 'bar'], ['baz', 42] ]

// objeto array-like
var obj = { 0: 'a', 1: 'b', 2: 'c' };
console.log(Object.entries(obj)); // [ ['0', 'a'], ['1', 'b'], ['2', 'c'] ]

Object.entries(obj).forEach(([key, value]) => {
    console.log(key + ' ' + value); // "a 5", "b 7", "c 9"
});
GutoTrosla

Object.Entries dalam JavaScript

// Object.entries() in javascript
const credits = { producer: 'John', director: 'Jane', assistant: 'Peter' };
const arr = Object.entries(credits);
console.log(arr);

/** Output:
[ [ 'producer', 'John' ],
  [ 'director', 'Jane' ],
  [ 'assistant', 'Peter' ]
]
**/
Chetan Nada

Jawaban yang mirip dengan “Entri objek JS”

Pertanyaan yang mirip dengan “Entri objek JS”

Lebih banyak jawaban terkait untuk “Entri objek JS” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya