map through array nodejs

I have a stripe function where I am trying to push the images into the array for each product. This is part of the prebuilt stripe checkout page… here’s my function at whole:

//defining arrays
var productsArray = [];
var priceArray = [];
var imageArray = [];
//query to database

var productsStripe = "select * from " + tableID + "";, function(err, conn) {
    if (err) return console.log(err);
  conn.query(productsStripe,  async function (err, rows) {
    if (err) {

    var itemName = ""
    var itemPrice = ""
    var totalNewPriceTest = ""

    for(var i = 0; i < rows.length; i++)     
    //inserting items and prices into arrays

            // loop over products array to construct the line_items
        const items =, i) => {
            return {
            price_data: {
                currency: 'CAD',
                product_data: {
                name: product,
                images: imageArray[i]
                unit_amount: parseInt(priceArray[i], 10) * 100,
            quantity: 1,

its returning the error: (node:39728) UnhandledPromiseRejectionWarning: Error: Invalid array

how do I get the image array to populate the stripe page with images too? I pushed the values into the array, and am calling them , but not sure why it is returning invalid array. any ideas?


  • imageArray is array containing image urls for different products, one for each product in the productArray.
  • From the name of the prop images, the error message and the error line info provided by the OP, the prop images ought to be an array.

In the code, image: imageArray[i] means that the image prop is assigned a string but it should be array. So changing it with [imageArray[i]], we are assigning an array of length one to image prop containing image url for that product.

Leave a Reply

Your email address will not be published. Required fields are marked *