[SOLVED]Please I want to output the value of object (cars) but I only get the index | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 2

[SOLVED]Please I want to output the value of object (cars) but I only get the index

https://code.sololearn.com/WeQWVPXdkHpQ/?ref=app

13th May 2022, 5:13 PM
Muhammad Awwal Yusuf
Muhammad Awwal Yusuf - avatar
6 Antworten
+ 1
https://code.sololearn.com/WeQWVPXdkHpQ/?ref=app Add link description place.. In question place , it won't work.. edit: try this Muhammad Awwal Yusuf for (let i in myObj.cars) { document.write(myObj.cars[i].name + "<br>") }
13th May 2022, 5:19 PM
Jayakrishna 🇮🇳
+ 1
Thanks Jayakrishna🇮🇳 it worked
13th May 2022, 5:37 PM
Muhammad Awwal Yusuf
Muhammad Awwal Yusuf - avatar
+ 1
But if I wanted to access the first array of the "models" of the car [0] alone, how do I do that?
13th May 2022, 5:38 PM
Muhammad Awwal Yusuf
Muhammad Awwal Yusuf - avatar
13th May 2022, 5:40 PM
Muhammad Awwal Yusuf
Muhammad Awwal Yusuf - avatar
+ 1
Solved other issues , thanks all
13th May 2022, 5:57 PM
Muhammad Awwal Yusuf
Muhammad Awwal Yusuf - avatar
+ 1
If according to your comment you only want to print "fiesta" your code would look like this: document.write(myObj.cars[0].models[0] + "<br>")
13th May 2022, 9:17 PM
Adrian