Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0125· OpenAIAi2 WildChat-4.8M (AI2)

create a object in array with products and values like pricr ccategory and namee. Use…

  1. User

    create a object in array with products and values like pricr ccategory and namee. Use find method and filter methos with arrow funtion.

  2. Assistant

    const products = [ { name: 'iPhone', price: 1000, category: 'Electronics' }, { name: 'Dress', price: 50, category: 'Fashion' }, { name: 'Keyboard', price: 30, category: 'Electronics' }, { name: 'Book', price: 20, category: 'Books' } ];

    // Using find method with arrow function const foundProduct = products.find(product => product.name === 'iPhone'); console.log(foundProduct);

    // Using filter method with arrow function const electronicProducts = products.filter(product => product.category === 'Electronics'); console.log(electronicProducts);

    // Output: // { name: 'iPhone', price: 1000, category: 'Electronics' } // [ { name: 'iPhone', price: 1000, category: 'Electronics' }, // { name: 'Keyboard', price: 30, category: 'Electronics' } ]