Is there a way to calculate the total number of JSON objects in the array and then recreate the same output based on that count?
var obj = [ {"id":"0","name":"Mike Johnson","group":1}, {"id":"1","name":"Bob Smith","group":2}, {"id":"2","name":"Richard Thomas","group":3}, {"id":"3","name":"Betty White","group":16}, {"id":"4","name":"Tim Thompson","group":3}, {"id":"5","name":"Carl Lewis","group":16}, {"id":"6","name":"Kathy Towers","group":3}, {"id":"7","name":"Billy Bob","group":1}, {"id":"8","name":"Sally Bailey","group":1} ];
First, I'd like to determine the count, and then recreate the output based on that count. The desired output should match the original input. for Count:-
var count = 0; function getCount() { for (var i = 0; i < obj.length; i++) { count++; } return count; }
for output :-
function showDetails() this is not giving the proper output { for(var j=0; j< count; j++){ obj.push([{j}]); } alert(obj.name); } alert(showDetails()); And I want an output like:- var obj = [ {"id":"0","name":"Mike Johnson","group":1}, {"id":"1","name":"Bob Smith","group":2}, {"id":"2","name":"Richard Thomas","group":3}, {"id":"3","name":"Betty White","group":16}, {"id":"4","name":"Tim Thompson","group":3}, {"id":"5","name":"Carl Lewis","group":16}, {"id":"6","name":"Kathy Towers","group":3}, {"id":"7","name":"Billy Bob","group":1}, {"id":"8","name":"Sally Bailey","group":1} ];
Does anyone know how to help me with this?