“JS Loop melalui objek” Kode Jawaban

Loop JavaScript melalui nilai objek

var myObj = {foo: "bar", baz: "baz"};
Object.values(myObj).map((val) => {
console.log(val);
})
// "bar" "baz"
Thoughtful Tamarin

JS Loop melalui objek

const obj = { a: 1, b: 2 };

Object.keys(obj).forEach(key => {
	console.log("key: ", key);
  	console.log("Value: ", obj[key]);
} );
GreekLover

JS Loop melalui objek

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

for (const property in object) {
  console.log(`${property}: ${object[property]}`);
}
Ugly Unicorn

JS Loop melalui objek

var p = {
    0: "value1",
    "b": "value2",
    key: "value3"
};

for (var key of Object.keys(p)) {
    console.log(key + " -> " + p[key])
}
Inquisitive Ibex

JS Loop melalui objek

const obj = { a: 1, b: 2, c: 3 }

for (const [key, value] of Object.entries(obj)) {
	console.log(key, value)
}
Impossible Ibis

JS Loop melalui objek

let obj = {name: "Mr X", sex: "Yes, 3 times a day"};
for (key in obj) {
	console.log(key, " ", obj[key])
}
Owais Ali

Jawaban yang mirip dengan “JS Loop melalui objek”

Pertanyaan yang mirip dengan “JS Loop melalui objek”

Lebih banyak jawaban terkait untuk “JS Loop melalui objek” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya