I am trying to create an array of all string which has length more than zero.
let sampleArray2:string[] = ["hello","world","angular","typescript"];
let subArray:string[] = sampleArray2
.map(() => sampleArray2
.find(val => val.length > 5)
);
console.log(subArray);
As expected, it is returning [ 'angular', 'angular', 'angular', 'angular' ]
I wanted it to print [ 'angular', 'typescript' ]
I am specifically looking for a solution which uses both map and find together to accomplish this. How can I fix this?
Note: Though filter
is a straightforward solution, I am trying to see if map and find can be used together to get the desired output.