“JavaScript Loop melalui objek” Kode Jawaban

JavaScript Loop melalui objek

var obj = { first: "John", last: "Doe" };

Object.keys(obj).forEach(function(key) {
    console.log(key, obj[key]);
});
Bald Eagle

JavaScript Loop melalui objek

for (var property in object) {
  if (object.hasOwnProperty(property)) {
    // Do things here
  }
}
Bald Eagle

JavaScript Loop melalui objek

var person={
 	first_name:"johnny",
  	last_name: "johnson",
	phone:"703-3424-1111"
};
for (var property in person) {
  	console.log(property,":",person[property]);
}
Grepper

JavaScript Loop melalui objek

const point = {
	x: 10,
 	y: 20,
};

for (const [axis, value] of Object.entries(point)) {
	console.log(`${axis} => ${value}`);
}

/** prints:
 * x => 10
 * y => 20
 */
cala_bruh

JavaScript Loop melalui objek

var p = {
    "p1": "value1",
    "p2": "value2",
    "p3": "value3"
};

for (var key in p) {
    if (p.hasOwnProperty(key)) {
        console.log(key + " -> " + p[key]);
    }
}
Motionless Meerkat

JavaScript Loop melalui objek

for (variable in object) {
  statement
}
friendly neighborhood googler

Jawaban yang mirip dengan “JavaScript Loop melalui objek”

Pertanyaan yang mirip dengan “JavaScript Loop melalui objek”

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

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya