Back to Bloginterview
Convert JSON key to values (vice-versa)
A simple way to convert json keys to value, this question is being in MNCs
interview

Input
var data = { first: 'John', last: 'Doe', email: '[email protected]' } Expected Output
{
John : first,
Doe : last,
'[email protected]' : email
} Solution
var data = { first: 'John', last: 'Doe', email: '[email protected]' };
var result = {};
for(var key in data)
{
if(data.hasOwnProperty(key))
{
result[data[key]]=key
}
}