I am trying to convert my answer in an object because it is showing an array in the console?
This is my object
const myObject = {0: 54,1: 77,2: 79,3: 39,4: 37,5: 15,6: 23,7: 2,8: 4,9: 8,s: 439,k: 84,i: 654,p: 441,t: 954,o: 799,m: 236,a: 936,n: 675,c: 556,e: 1211,l: 597,g: 117,u: 596,r: 973,h: 200,f: 239,d: 284,b: 176,y: 281,w: 88,v: 174,j: 53,x: 79,'[': 65,']': 65,q: 11,_: 32,z: 3,};
Here I sort the object according to values:
const myObject = {0: 54,1: 77,2: 79,3: 39,4: 37,5: 15,6: 23,7: 2,8: 4,9: 8,s: 439,k: 84,i: 654,p: 441,t: 954,o: 799,m: 236,a: 936,n: 675,c: 556,e: 1211,l: 597,g: 117,u: 596,r: 973,h: 200,f: 239,d: 284,b: 176,y: 281,w: 88,v: 174,j: 53,x: 79,'[': 65,']': 65,q: 11,_: 32,z: 3,};
const finalAns = Object.entries(myObject).sort(function (a, b) {
return b[1] - a[1];
});
console.log(finalAns);
This is my output of consol.log.
I am getting finalAns
as an Array, but I want to print answer as an object and the object should be sorted according to its values?