Javascript enigmes Flashcards

1
Q

ça affiche quoi ?

< p id=”demo”></p>
< script>
const person = {
name: “John”,
age: 30,
city: “New York”
};
document.getElementById(“demo”).innerHTML = person;
</script>

A

[object Object]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

afficher chaque VALEUR d’un objet

A

let text = “”;
for (let x in objet) {
text += objet[x] + “ “;
};
document.getElementById(“demo”).innerHTML = text;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

afficher chaque CLE et VALEUR d’un objet

A

const capitales = {
france:”Paris”,
espagne:”Madrid”,
equateur:”Quito”,
pérou:”Lima”
};
let text=””;
for (let [pays, capitale] of Object.entries(capitales)) {
text += pays + ‘: ‘ + capitale + ‘< br>’
};
document.getElementById(‘demo’).innerHTML=text;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Créer un array avec les valeurs d’un objet

A

const capitales = {
france:”Paris”,
espagne:”Madrid”,
equateur:”Quito”,
pérou:”Lima”
};

const myArray = Object.values(capitales)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Comment itérer à travers les paires [clé: valeur] d’un objet ?

A

text = ‘’
for (let [clé, valeur] of Object.entries(myArray)) {
text += clé + “, “ + valeur + < br>;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly