map values in an array to values in another array in Javascript map values in an array to values in another array in Javascript

please I have 2 arrays in the following format

const images = ["image1", "image2", "image3", "image4"]

const items = [{quantity: 1}, {quantity: 2}, {quantity: 4}, {quantity: 1}]

I need the final output to be like below

const newArray = [
    {
        image: "image1",
        quantity: 1
    },
    {
        image: "image2",
        quantity: 2
    },
    {
        image: "image3",
        quantity: 4
    },
    {
        image: "image4",
        quantity: 1
    },
]


from Stackoverflow

Comments

Popular posts from this blog

\\u0000 cannot be converted to text error \\u0000 cannot be converted to text error

How to create @click on select menu in VueJS How to create @click on select menu in VueJS

Using Ts-Standard linting, JSDoc comment at beginning of file triggers "This rule requires the `strictNullChecks` compiler option" error Using Ts-Standard linting, JSDoc comment at beginning of file triggers "This rule requires the `strictNullChecks` compiler option" error