JSFiddle - React, Tailwind, and code Playground

by zav19791979

JavaScript

function someFunc () {
    const arr = [
        {
            title: 'some title',
            count: 1,
            price: 25
        }
    ]

    function checkItem(arr, title) {
        const index = arr.findIndex((item) => item.title === title);
        
        return index === -1 ? 'не удалось найти элемент' : `индекс элемента ${index}`;       
    }

    console.log(checkItem(arr, 'some title'));
    console.log(checkItem(arr, 'some not exist title'));
}

someFunc ()