Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

why array.map returns undefined

let test = [ {name:'test',lastname:'kumar',age:30},
             {name:'test',lastname:'kumar',age:30},
             {name:'test3',lastname:'kumar',age:47},
             {name:'test',lastname:'kumar',age:28},
             {name:'test4',lastname:'kumar',age:30},
             {name:'test',lastname:'kumar',age:29}]

let result1 = test.filter(element => 
              { 
                 if (element.age === 30) 
                 {
                    return element;
                 }
              }).map(({lastname})=>lastname)
console.log(result1);
output : ['kumar','kumar','kumar']
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #returns #undefined
ADD COMMENT
Topic
Name
7+2 =