0
I am using a script that sorts a JSON in alphabetical order with indicative header, as shown in this question however I am not able to make it work in harmony with prototype, returns me the error:
Cannot read property '0' of undefined
I have no idea how to solve because in fact the script is not even mine, so I’m lost, I wanted to solve it. Here’s the script:
var itens = JSON.parse('[{"user_id":"3333","username":"cacau"},{"user_id":"3333","username":"balmer"}]');
itens.sort(function(a,b){
return a.username.localeCompare(b.username);
});
var letras = {};
for(var i in itens) {
console.log(itens);
var l = itens[i].username[0].toUpperCase();
letras[l] = letras[l] || [];
letras[l].push(itens[i]);
}
for(var letra in letras) {
document.write('LETRA ' + letra + "<br />");
for(var k in letras[letra]) {
document.write(letras[letra][k].username + "<br />");
}
document.write('<br />');
}
A fiddle playing the error https://jsfiddle.net/5h708bxj/1/
Note: The lib prototype.js is being used together with this code.
Question with this template becomes difficult to help you and future users with the same question. See How to create a Minimum, Complete and Verifiable example
– rubStackOverflow
The answer is no... I can only show a link to my website with problems?... If by any chance you fix the question, tap to remove my -1. Thank you!
– brasofilo