Search code examples
javascriptarraysobjectreturn

Console.log output vs return output not the same?


Ive never experienced this and maybe someone could explain to me whats happening?

const columns = Object.values(props[1]).map((x, i) =>{
            console.log(x) <- output: {name: "companyName", label: "Company", dataType: "string", width: 200, tooltip: "", …}
            return x
        })

console.log(columns) <- output: (4) [{…}, {…}, {…}, {…}]

Why are they outputting differently? I need it to look like the console.log(x) inside the map. I assumed console.log(x) and console.log(columns) would be the same.


Solution

  • you are presumably mapping 4 values in props[1] to be {name:....} and assigning it to columns thus getting [{...}, {...}, {...}, {...}]

    of-course, columns is not same as x but [ x, x, x, x]