Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript find in nested array

const products = [
  { id: 01,
    items: [ { id: 01, name: 'apple' },
             { id: 02, name: 'banana'},
             { id: 03, name: 'orange'}]},
  { id: 02,
    items: [ { id: 01, name: 'carrot' },
             { id: 02, name: 'lettuce'},
             { id: 03, name: 'peas'   }]},
  { id: 03,
    items: [ { id: 01, name: 'eggs'  },
             { id: 02, name: 'bread' },
             { id: 03, name: 'milk'  }]}
 ]

    let found;
    for ( const category of products ){
        found = category.items.find( item => item.name == "milk" )
        if ( found ) break
    }
    console.log( found ) 
    // == { id: 3, name: 'milk' }
 Run code snippet
Comment

nested arrays javascript

var arr = [[3],[4]]
Comment

PREVIOUS NEXT
Code Example
Javascript :: usecontext react 
Javascript :: split string into two parts javascript 
Javascript :: image view component react js 
Javascript :: how to add eslint to react project 
Javascript :: javascript get width 
Javascript :: js use restrict 
Javascript :: react-bootstrap sidebar 
Javascript :: node convert string to hash 
Javascript :: sending value in input angular material 
Javascript :: angular how to check a radiobox 
Javascript :: setAttribute is not a function jquery 
Javascript :: object methods in javascript 
Javascript :: select selectedindex jquery 
Javascript :: lodash merge 
Javascript :: Type writer in react 
Javascript :: how to filter array in javascript 
Javascript :: react native create text file 
Javascript :: months js 
Javascript :: react bootstrap sweetalert2 
Javascript :: kick commands discord.js 
Javascript :: math.max js 
Javascript :: typeof javascript 
Javascript :: async await iife 
Javascript :: generate angular component in a folder 
Javascript :: nodejs http get request to external server 
Javascript :: cors error in node js express 
Javascript :: How To Add A New Element To HTML DOM 
Javascript :: javascript filter 
Javascript :: js variable 
Javascript :: navlink activestyle not working 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =