M
M
Makcimka2020-11-09 07:35:49
JavaScript
Makcimka, 2020-11-09 07:35:49

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

Why is the map() method returning the length of the array in this code? Logically, after all, the object should be pushed

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 it will work if i write
let newArr = arr.map((keyValue)=>{
return keyValue
})
newArr.push({newTestKey: 'new-test-value'})
console.log(newArr)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-11-09
@Makcimka

push

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question