DEV Community 👩‍💻👨‍💻

Discussion on: Cool Object methods in JavaScript

avalander profile image

What would you do with the output of entries though?

It's quite useful to convert objects to other formats, like query strings or SQL queries:

const query {
  page: 3,
  type: 'unicorn',

const toQueryString = query =>
  '?' + Object.entries(query)
    .map(([ key, value ]) => [ key, value ].join('=')) // Or .map(x => x.join('='))

toQueryString(query) // '?page=3&type=unicorn'
squigglybob profile image

Yep, that's nice. Object.keys(obj) always bothered me as then you needed to grab the value from the obj with the index of the key, but this way you have it there when you map etc.