Answers for "how to define array in json"

3

create array from htmlcollection

//Use the Array.from() method to convert a nodelist or HTMLcollection into an array.

let elements = document.getElementsByClassName("classnameHere");
let arrayOfElements = Array.from(elements);

//Now arrayOfElements is iterable with methods such as .forEach().
Posted by: Guest on March-03-2020
7

json example array

{
	"name":"John",
	"age":30,
	"cars":[ "Ford", "BMW", "Fiat" ]
}

// Another exemple
{
    "people": [
        {
            "website": "stackabuse.com",
            "from": "Nebraska",
            "name": "Scott"
        },
        {
            "website": "google.com",
            "from": "US",
            "name": "Zuck"
        }
    ]
}
Posted by: Guest on January-14-2021
1

js create json array

var employees = {
    accounting: []
};

for(var i in someData) {    

    var item = someData[i];   

    employees.accounting.push({ 
        "firstName" : item.firstName,
        "lastName"  : item.lastName,
        "age"       : item.age 
    });
}
Posted by: Guest on October-30-2020
0

Array as JSON

const text = '["Ford", "BMW", "Audi", "Fiat"]';

const myArr = JSON.parse(text);
Posted by: Guest on August-05-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language