how to create json array in javascript?

how to create json array in javascript – Arrays in JSON are almost the same as arrays in JavaScript. In JavaScript, you can use JSON.stringify to convert an array or values into a JSON formatted string.

how to create json array in javascript

The first method will use for loop for creating JSON array from an input array. Syntax of Arrays in JSON Objects: JSON is JavaScript Object Notation is used for data interchange, Array of strings is an ordered list of values with string type.

create json array in javascript

json example array

{
	"name":"Mehul",
	"age":30,
	"mobiles":[ "Oppo", "Nokia", "Moto" ]
}

// Another exemple
{
    "people": [
        {
            "website": "w3diy.com",
            "from": "USA",
            "name": "Bhavika"
        },
        {
            "website": "infinityknow.com",
            "from": "PK",
            "name": "Ummides"
        }
    ]
}

js create json array

var members = {
    accounting: []
};

for(var i in companyDetails) {    

    var item = companyDetails[i];   

    members.accounting.push({ 
        "MemberUserName" : item.MemberUserName,
        "memberSirname"  : item.memberSirname,
        "age"       : item.age 
    });
}

json arrays

{
  "array": [{1,2,3,4,5,6}]
}

Don’t Miss : json to array php

javascript create json object from array

var array = ['a', 1, 'b', 2, 'c', 3],
    object = {},
    i

for (var i = 0; i < array.length; i += 2) {
    object[array[i]] = array[i + 1];
}

console.log(object);

Hwo to access arary in json

console.log(productJS);
console.log(productJS[0].eee1);
console.log(productJS[0].comments[0]);

I hope you get an idea about how to create json array in javascript.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment