So here's the thing. I have 3 inputboxes that function as table cells(the header). I also run a script that, if one of the inputboxes' input has changed, fires a function that fetches data from my database, using an ajax request. A json is returned. Now I fetch objects from the data(json) returned, so I get something like {key1: '1', key2: 'myName', ...}. Now, the "problem" is that I don't know what the keynames are(I know the keynames but I don't want to use them). Yet I want all of the keys' values listed in separate arrays.
The script I have right now:
$.ajax({ //ajax request
method: "POST",
url: "../php/fetch.php",
data: inputs,
dataType: 'json',
cache: false,
success: function(data) {
var j=0;
var otp;
for(var i = 0; i < data.length; i++) {
var obj = data[i];
console.log(obj.length);
for(p=0; p<obj.length; p++){
otp = obj[0];
console.log(otp);
j++;
}
}
}
})
So I have written the code above but I get stuck at assigning the values. How do I get all keyvalues into separate arrays without knowing the column_names?
EDIT: I don't want to get the key values but I want to get the keyvalues their own array that contains the values from the database (of this particular key).
Example:
A json is returned [{key1: "value1", key2: "value2", /*more values*/...}, {key1: "value10", key2: "value20", /*more values*/...}]
something like that. I create an obj
that contains "a part of the json", like this {key1: "value1", key2: "value2", /*more values*/...}
.
What I want:
I want to create an array from the obj
that contains ["value 1", "value10"]
in this case for key1
. So for every key1
value in the json, get it and put it in an array.
I already tried obj.keys[0]
but that returns 0 as a value (which doesn't match any value in my json at all)
Thank you very much for your help in advance! :)
Evoc
Ps. if anything is unclear feel free to ask, of course.