Skip to content

Instantly share code, notes, and snippets.

@allonsmandy
Created April 21, 2020 18:30
Show Gist options
  • Select an option

  • Save allonsmandy/c970b4253f26539af65c4f68f7a8ee03 to your computer and use it in GitHub Desktop.

Select an option

Save allonsmandy/c970b4253f26539af65c4f68f7a8ee03 to your computer and use it in GitHub Desktop.

Revisions

  1. allonsmandy created this gist Apr 21, 2020.
    19 changes: 19 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    const exampleArray = [ [ [ 'value' ] ] ]

    // bad
    exampleArray.forEach((array1) => {
    array1.forEach((array2) => {
    array2.forEach((el) => {
    console.log(el)
    })
    })
    })

    //good
    const retrieveFinalValue = (element) => {
    if(Array.isArray(element)) {
    return retrieveFinalValue(element[0])
    }

    return element
    }