I would like to convert Json data to an array Javascript, that I can access like using array[0][0], someone can help me please.
[
{
"Login": "test1",
"Nom": "test1",
"Prenom": "test1p",
"password": "124564",
"Email": "[email protected]"
},
{
"Login": "test2",
"Nom": "test2",
"Prenom": "test2p",
"password": "124564",
"Email": "[email protected]"
}
]
I tried this piece of code but nothing happen , I can't access to a specific(Exemple I would like to have Nom) data in array using for example array[0][1].
Code.js
var data = [
{
"Login": "test1",
"Nom": "test1",
"Prenom": "test1p",
"password": "1267846",
"Email": "[email protected]"
},
{
"Login": "test2",
"Nom": "test2",
"Prenom": "test2p",
"password": "124494",
"Email": "[email protected]"
}
];
function data_to_array(data) {
var array = [];
for (var key in data) {
var value = data[key];
if (typeof value === 'string') {
array[key] = value;
} else {
array[key] = data_to_array(value);
}
}
return array;
}
var array = data_to_array(data);
for(var i in array)
console.log(array[i]);
Once parsed, if I try to access it using myArr[0][1], it shows as undefined.
for..in
with an array. What is the expected output? – thefourtheye Apr 2 at 8:12for (var i=0,......
– Satpal Apr 2 at 8:13data
is not JSON, it is itself an array. What are you trying to achieve here? – RGraham Apr 2 at 8:15