Search code examples
javascriptnode.jsnode-mysql

javascript array clarification


I'm new to Javascript and have this issue:

console.log(results1[1]);

prints: [ { product_identification_category_id: 1, title: 'Title1' } ]

console.log(results1[1].product_identification_category_id);

prints undefined. I was expecting this to print 1.

Am I misunderstanding something? What am I doing wrong?

Thanks!


Solution

  • Looks to me like results1[1] is, itself, an array (with one entry). So you'd want

    console.log(results1[1][0].product_identification_category_id);
    // The new bit --------^^^