Why does the map () method return the length of the array?

  • 0
    Why does the map () method return the length of the array in this code? Logically, the object should push.
    const arr = [
        {testKey: 'test-value'},
        {testKey1: 'test-value1'},
        {testKey2: 'test-value2'},
        {testKey3: 'test-value3'},  
    ]
    
    let newArr = arr.map((keyValue)=>{
        return keyValue
    }).push({newTestKey: 'new-test-value'})
    
    console.log(newArr) // возвращает 5


    I know that it will work if you write
    let newArr = arr.map ((keyValue) = & gt; {
    return keyValue
    })
    newArr.push ({newTestKey: 'new-test-value'})
    console.log (newArr)
    JavaScript Anonymous, Jul 20, 2020

  • 1 Answers
  • 0
    push

    Return value

    The new length property of the object upon which the method was called.
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!