Here is my Input Could you all help me out to get the all object based on values as list
{
Jack: 2,
olive: 1,
harry: 2
}
Want my output to be
harry = 2
olive = 1
jack = 2
Let me know if there is a way to get the output as mentioned above in javascript
You can use the function Object.entries(object) and loop over all the entries to log the information how you want.
For more information on Object.entries(object) visit https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries
const data = {
Jack: 2,
olive: 1,
harry: 2
};
const entries = Object.entries(data);
entries.forEach(([key, value]) => console.log(`${key} = ${value}`));
You could try the following:
const result = Object.entries(theObject).map(([key, value]) => `${key.toLowerCase((} = ${value}`).join(‘\n’);
console.log(result);
Hopefully that helps!
Please check Object.entries() or Object.keys().
Object.entries():- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries
Object.keys():- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys