swati-jagtap / javascript-practice

0 stars 0 forks source link

7.3.14--Write a function called modifyArray takes array as parameter and modifies the fifth item of the array and return the array. If the array length is less than five it return 'item not found'. #74

Open swati-jagtap opened 3 years ago

swati-jagtap commented 3 years ago

7.3.14--Write a function called modifyArray takes array as parameter and modifies the fifth item of the array and return the array. If the array length is less than five it return 'item not found'.


function modifyArray(arr)
{
    if(arr.length<5)return `Item not found`;
    else{
        arr[4]="xyzah";
        return arr;
    }
}

console.log(modifyArray(['Avocado', 'Tomato', 'Potato','Mango', 'Lemon','Carrot']));
console.log(modifyArray(['Google', 'Facebook','Apple', 'Amazon','Microsoft',  'IBM']));
console.log(modifyArray(['Google', 'Facebook','Apple', 'Amazon']));
`

output

image