Can anyone assist me in converting Json data to a Javascript array that can be accessed using array[0][0]?
[
{
"Login": "test1",
"Nom": "test1",
"Prenom": "test1p",
"password": "124564",
"Email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="097d6c7a7d38496e64686065276a6664">[email protected]</a>"
},
{
"Login": "test2",
"Nom": "test2",
"Prenom": "test2p",
"password": "124564",
"Email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a1d5c4d2d593e1c6cc120a">[email protected]</a>"
}
]
I have tried the provided code but I am unable to access specific data (such as 'Nom') in the array. How can I achieve this?
Code.js
var data = [
{
"Login": "test1",
"Nom": "test1",
"Prenom": "test1p",
"password": "1267846",
"Email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="becadbcdca8ffed9de7bfdfd20ed3d123bbde94dec39b959599dd99">[email protected]</a>"
},
{
"Login": "test2",
"Nom": "test2",
"Prenom": "test2p",
"password": "124494",
"Email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="13677660672153747e727a7f3d707c792528398b97291d29">[email protected]</a>"
}
];
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]);
After parsing, trying to access it with myArr[0][1] results in 'undefined'.