Skip to content

Array#flat doesn't work after push in one of the nested arrays #2018

Closed
@mateuszJS

Description

@mateuszJS

Current behaviour: flat() is returning array with zero length
Expected behaviour: flat() should make all items flatten, so it should be [1,3,2,3], so length = 4

export function getData(): void {
  let arr: f32[][] = [[1], [2]]

  let flattenArray = arr.map<f32[]>(nestedArray => {
    nestedArray.push(3)
    trace("nestedArray.length", 1, nestedArray.length)
    return nestedArray
  }).flat()

  trace("flattenArray.length", 1, flattenArray.length)
}

link to example

Interesting facts:

  • if initial input will be changed from let arr: f32[][] = [[1], [2]] to let arr: f32[][] = [[1]], then Array#flat is working correctly
  • of course when push from 5 line is removed, then Array#flat is also working correctly

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions