How to get item where id is: '60da3d5ce6cdd45d6dbc56bd'?
            Asked
            
        
        
            Active
            
        
            Viewed 37 times
        
    0
            
            
         
    
    
        Maik Lowrey
        
- 15,957
- 6
- 40
- 79
 
    
    
        shanksu 218
        
- 185
- 1
- 14
- 
                    Could you describe your case better: what the structure of your data is, provide an example in code? Did you try this https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find? – Źmicier Jaraševič Dec 11 '21 at 11:09
1 Answers
0
            
            
        Use
- flat function => https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat 
- filter function => https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find 
It will return the first value satisfying condition
Something like:
const data = [
  [{_id: 1}, {_id: 2}, {_id: 2}, {_id: '60da3d5ce6cdd45d6dbc56bd'}],
  [{_id: 1}, {_id: 2}, {_id: 2}],
  [{_id: 1}, {_id: 2}, {_id: 2}]
]
data.flat().find(e => e._id === '60da3d5ce6cdd45d6dbc56bd')
// output { _id: '60da3d5ce6cdd45d6dbc56bd' }
works just fine
 
    
    
        millenion
        
- 1,218
- 12
- 16
- 
                    thank you for the answer but im gettting all the items as one array instead of just the item that matches the id – shanksu 218 Dec 11 '21 at 12:16
- 
                    
- 
                    yes it works now in the console but when i try to use it example: `data.name` im getting this errorr 'Cannot read properties of undefined (reading 'name')'. thank you – shanksu 218 Dec 11 '21 at 13:25
- 
                    
