how to push the object keys and values to array

I need to push the key value pair to new array and should build the mongodb $match query.

const queryFormat = (payload) => {
    delete payload.userEventId
    var query = {}
     var res = []
    for(key in payload) {
       res.push( {key:payload[key]})
    query['$match'] = {"$and" :res}

const payload = {
    id :1,
    name : 'Alfred',
    location : 'moon'

expected output


output I got


How to deal with it

17 thoughts on “how to push the object keys and values to array”

  1. Unquestionably believe that which you stated. Your favorite justification seemed to be on the net the easiest thing to
    be aware of. I say to you, I definitely get irked while people consider worries that they
    plainly do not know about. You managed to hit the
    nail upon the top and also defined out the whole thing without having side-effects , people can take a signal.

    Will probably be back to get more. Thanks


Leave a Comment