I would like to tinker arrays from which I can assemble the following JSON file, so far everything works, I just can’t get any further at this point:
var T_nn_IN = document.getElementById('datatablenewname');
var tabledata_newname_initialname = [];
var tabledata_newname_newname = [];
var tabledata_newname_rev = [];
// var tabledata_newname_IN2 = [];
$(T_nn_IN).find('> tbody > tr > td').each(function () {
//tabledata_newname_IN1.push($(this).html())
if($(this).hasClass("initialname") == true){
tabledata_newname_initialname.push($(this).html())
}
if($(this).hasClass("newname") == true){
tabledata_newname_newname.push($(this).html())
}
if($(this).hasClass("rev") == true){
tabledata_newname_rev.push($(this).html())
myJSONtable.push({"Satz.Ursprungsdateien":tabledata_newname_initialname})
myJSONtable.push({"Satz.NeuerName":tabledata_newname_newname})
myJSONtable.push({"Satz.Revision":tabledata_newname_rev})
}
Here you can see how it should look after the function has been run:
{
"Satz": [
{
"Ursprungsdateien": "placeholder1",
"NeuerName": "placeholder1",
"Revision": "05"
},
{
"Ursprungsdateien": "placeholder2",
"NeuerName": "placeholder2",
"Revision": "04"
},
{
"Ursprungsdateien": "placeholder3",
"NeuerName": "placeholder3",
"Revision": "02"
},
{
"Ursprungsdateien": "placeholder4",
"NeuerName": "placeholder4",
"Revision": "02"
}
]
}
And here you can See what I actually get jet:
Satz.Ursprungsdateien: (4) ["placeholder1", "placeholder2", "placeholder3", "placeholder4"]
Satz.NeuerName: (4) ["placeholder1", "placeholder2", "placeholder3", "placeholder4"]
Satz.Revision: (4) ["05", "04", "02", "02"]
Where or how do I have to push the data so that it looks like it should.
So in the end I want 4 arrays each filled with a Satz.Ursprungsdateien, a Satz.NeuerName and a Satz.Revision.
thank you in advance.
Hi you are pushing object in wrong way, you need to create array then push object into that array
Replace these lines
With this
Updated
Replace this
with
That worked really well so far, now I only get this 4 times, how can I get around this?
enter image description here