DEV Community

amitatall4u
amitatall4u

Posted on

Javascript : is it possible to get output without undefine value? with return value .

const array = [1,2,4,9,16,25,36,49,64,81,100];
const newArray = array.map((currentElement,index,arrayValue) => {if (index > 7){
return Index No : ${index} and value : ${currentElement} of array : ${arrayValue};}
});
console.log(newArray);

output :

[
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
'Index No : 8 and value : 64 of array : 1,2,4,9,16,25,36,49,64,81,100',
'Index No : 9 and value : 81 of array : 1,2,4,9,16,25,36,49,64,81,100',
'Index No : 10 and value : 100 of array : 1,2,4,9,16,25,36,49,64,81,100'
]

Top comments (0)