I have an array which consists of the string elements something like this:
a = ['First Name', 'Last Name', 'Age']
the actually array is quite large so I have given a small example here.
I have another Json object which has few elements already:
jsonschema = {
'creationDate': date,
'schemaVersion': 1.5
}
I would like to loop through my array and add the elements to my jsonarray something like this:
jsonschema = {
'creationDate': date,
'schemaVersion': 1.5,
'new arraylist':[
"First Name",
"Last name",
"Age"
]
}
I tried quite a few things mentioned in the StackOverflow but for some reason nothing seems to work for me. Can someone please help me with this?
Here is what I have been trying using the for loop:
for(var o=0; o<a.length; o++)
{
jsonschema['new arraylist'] = a[o];
}
In this case I am getting only the last element of the array.
How can I elements to JsonArray with {}
I have a Json element already something like this
jsonschema = {
'creationDate': date,
'schemaVersion': 1.5,
}
I would like to add new element and it should appear something like this:
jsonschema = {
'creationDate': date,
'schemaVersion': 1.5,
'newElement':{
'value without kex'
}
}
I am able to achieve this but I am not getting the {}
how can I add the single value with {}