Search code examples
javascriptarraysamazon-web-servicesobjectfor-in-loop

ReferenceError: string is not defined


I try to do iteration on object on nodejs using for in, on my local it's working just fine. but when i deploy it to web service, it pass an error.

but when i tried on my local it work just fine

const queue = {
    mobilize : 'test',
    mobileTurnOn: 'mobileTurnOn',
    pushAdminNotif: 'pushAdminNotif',
    diffLocationAlert: 'diffLocationAlert'
  };
  for ( string in queue) {
    console.log(string, "key")
    console.log(queue[string], "value")
  };

it said variable is not defined

ReferenceError: string is not defined 13 at /app/dist/app.js:59:10 12 at /app/node_modules/amqplib/callback_api.js:15:23 11 at /app/node_modules/amqplib/lib/connect.js:154:9 10 at succeed (/app/node_modules/amqplib/lib/connection.js:283:5) 9 at onOpenOk (/app/node_modules/amqplib/lib/connection.js:262:5) 8 at /app/node_modules/amqplib/lib/connection.js:165:32 7 at /app/node_modules/amqplib/lib/connection.js:159:12 6 at Socket.recv (/app/node_modules/amqplib/lib/connection.js:507:12) 5 at Object.onceWrapper (events.js:420:28) 4 at Socket.emit (events.js:314:20) 3 at Socket.EventEmitter.emit (domain.js:483:12) 2 at emitReadable_ (_stream_readable.js:557:12) 1 at processTicksAndRejections (internal/process/task_queues.js:83:21)

here is my terminal on my local running


Solution

  • You can try this:

    for (const string in queue) {
      console.log(string, "key")
      console.log(queue[string], "value")
    };