Let arr =["string","array","hello",null, undefined];
Find the length of each string But null , undefined length should be return 0
By using array map function
const arr =["string","array","hello",null, undefined]
const A = arr.map(myFunction)
function myFunction(arr[i]) {
for (let i = 0; i < 4; i++) {
if (arr[i]==null || arr[i]==undefined) {
A[i]=0;
} else {
A[i]=arr[i].length;
}
Comments
Leave a comment