Chrome Extension

Order and find elements

carlist.map(element => 
console.log(element.brand +" = "+ element['models'].length )); 

console.log("result ==" + JSON.stringify(carlist.filter(element => element['brand'] ==  'Renault'),null,4)); 



var formatedlsit = []; 
var asceding = []; 
var desceding = []; 


formatedlsit = carlist.map(item => ({
        brand: item.brand,
        totalOfmodels: item.models.length
}));


console.log('--------------------------------------------------')

//console.log('formatedlist');
//console.log(JSON.stringify(formatedlsit, null, 4 ));

/*  asceding = formatedlsit.sort(function(a, b){return a.totalOfmodels - b.totalOfmodels});
desceding =  formatedlsit.sort(function(a, b){return b.totalOfmodels - a.totalOfmodels}); 
console.log('------------------ crescente--------------------------------')
console.log(JSON.stringify(asceding, null, 4 ));
console.log('-------------------decrescente-------------------------------')
console.log(JSON.stringify(desceding, null, 4 ));
console.log("mais modelos " + asceding[0].brand);
console.log("menos modelos" + desceding[0].brand);  */ 

 console.log(formatedlsit.sort(function(a, b){return a.totalOfmodels - b.totalOfmodels}));
console.log(formatedlsit.sort(function(a, b){return b.totalOfmodels - a.totalOfmodels}));
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool
Was this helpful?
0 Comments