Pass JSON into JavaScript Array

Pass JSON into JavaScript Array

The JavaScript/jQuery code-sample

var students = [];
var studentsJSON = [{ "name": "Anil" }, { "name": "Sunil " }, { "name": "Sushil" }];

//The for each of data.
studentsJSON.forEach(function (item) {
    students.push(item.name);
});

alert(JSON.stringify(students));


The Live demo code-sample for Pass JSON into JavaScript Array

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Pass JSON intoJavaScript Array</title>
    <script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
    <script>
        var students = [];
        var studentsJSON = [{ "name": "Anil" }, { "name": "Sunil " }, { "name": "Sushil" }];  

        //The for each of data.
        studentsJSON.forEach(function (item) {
            students.push(item.name);
        });

        alert(JSON.stringify(students));
    </script>
</head>
<body>
    <h1>Pass JSON into JavaScript Array</h1>
</body>
</html>




ANIL SINGH

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Buy Books Online at Best Prices

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.