Sfida: Esplorare le Proprietà degli Oggetti con l'Iterazione
Compito
Viene fornito un oggetto che rappresenta il rame. L'obiettivo è iterare sulle proprietà dell'oggetto copper utilizzando il ciclo for...in. Per ogni proprietà, è necessario registrare sia il nome della proprietà che il suo valore nella console.
- Utilizzare il ciclo
for...inper scorrere le proprietà dell'oggettocopper. - Per ogni proprietà, registrare un messaggio nella console nel formato:
"Property: [property name], Value: [property value]".
12345678910const copper = { symbol: "Cu", atomicNumber: 29, meltingPoint: "1984.32 °F", appearance: "Red-orange metallic luster", }; ___ (let key ___ copper) { ___(`Property: ${___}, Value: ${___[___]}`); }
Output atteso:
Property: symbol, Value: Cu
Property: atomicNumber, Value: 29
Property: meltingPoint, Value: 1984.32 °F
Property: appearance, Value: Red-orange metallic luster
- Per iterare sulle proprietà dell'oggetto, utilizzare il ciclo
for...in. Iniziare confor (let key in copper) { ... }. - All'interno del ciclo, accedere al valore della proprietà tramite
copper[key]. - Utilizzare
console.log()per stampare i messaggi nel formato richiesto.
12345678910const copper = { symbol: "Cu", atomicNumber: 29, meltingPoint: "1984.32 °F", appearance: "Red-orange metallic luster", }; for (let key in copper) { console.log(`Property: ${key}, Value: ${copper[key]}`); }
Grazie per i tuoi commenti!
Chieda ad AI
Chieda ad AI
Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione
Can you explain how the for...in loop works in this example?
What happens if the object has nested properties?
Can you show how to skip inherited properties in the loop?
Awesome!
Completion rate improved to 2.27
Sfida: Esplorare le Proprietà degli Oggetti con l'Iterazione
Scorri per mostrare il menu
Compito
Viene fornito un oggetto che rappresenta il rame. L'obiettivo è iterare sulle proprietà dell'oggetto copper utilizzando il ciclo for...in. Per ogni proprietà, è necessario registrare sia il nome della proprietà che il suo valore nella console.
- Utilizzare il ciclo
for...inper scorrere le proprietà dell'oggettocopper. - Per ogni proprietà, registrare un messaggio nella console nel formato:
"Property: [property name], Value: [property value]".
12345678910const copper = { symbol: "Cu", atomicNumber: 29, meltingPoint: "1984.32 °F", appearance: "Red-orange metallic luster", }; ___ (let key ___ copper) { ___(`Property: ${___}, Value: ${___[___]}`); }
Output atteso:
Property: symbol, Value: Cu
Property: atomicNumber, Value: 29
Property: meltingPoint, Value: 1984.32 °F
Property: appearance, Value: Red-orange metallic luster
- Per iterare sulle proprietà dell'oggetto, utilizzare il ciclo
for...in. Iniziare confor (let key in copper) { ... }. - All'interno del ciclo, accedere al valore della proprietà tramite
copper[key]. - Utilizzare
console.log()per stampare i messaggi nel formato richiesto.
12345678910const copper = { symbol: "Cu", atomicNumber: 29, meltingPoint: "1984.32 °F", appearance: "Red-orange metallic luster", }; for (let key in copper) { console.log(`Property: ${key}, Value: ${copper[key]}`); }
Grazie per i tuoi commenti!