Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (7k points)

This is my object:

var students = [

    {

        name: "Pavel Ravel",

        track: "CSS, HTML5, jQUery",

        achievements: "145",

        points: "353"

    },

    {

        name: "Steve Jobs",

        track: "MacOS, iOS",

        achievements: "3958735",

        points: "09854"

    },

    {

        name: "Bill Gates",

        track: "Windows",

        achievements: "358798",

        points: "37593"

    },

    {

        name: "Gabe Newel",

        track: "Steam",

        achievements: "5302",

        points: "3052"

    },

    {

        name: "Steve Wozniak",

        track: "Apple 1 and 2",

        achievements: "23562",

        points: "3525632"

    }

];

What should I do for document.write variable students? I have created a for in loop but it wirtes only undefined

for ( var studentsList in students ) {

    document.write(studentsList[students]);

}

The goal is to write this into the document:

name: "Pavel Ravel", track: "CSS, HTML5, jQUery", achievements: "145", points: "353"

1 Answer

0 votes
by (13.1k points)

You can use JSON.stringify() like this:

var students = [

    {

        name: "Pavel Ravel",

        track: "CSS, HTML5, jQUery",

        achievements: "145",

        points: "353"

    },

    {

        name: "Steve Jobs",

        track: "MacOS, iOS",

        achievements: "3958735",

        points: "09854"

    },

    {

        name: "Bill Gates",

        track: "Windows",

        achievements: "358798",

        points: "37593"

    },

    {

        name: "Gabe Newel",

        track: "Steam",

        achievements: "5302",

        points: "3052"

    },

    {

        name: "Steve Wozniak",

        track: "Apple 1 and 2",

        achievements: "23562",

        points: "3525632"

    }

];

Want to be a full stack developer? Check out the full stack developer course from Intellipaat. 

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...